layui.define(['jquery', 'element', 'util', 'form', 'map', 'laytpl', 'slider', 'colorpicker', 'laypage'], function(
	exports) {
	"use strict";
	var MODULE_NAME = 'mapUI',
		MODEL_EDIT = 'edit',
		MODEL_VIEW = 'view',
		DEFAULT_CONTAINER_ID = 'map',
		LAYER = 'layer-',
		MAP_CONTAINER_CLASS_NAME = 'map-edit-container',
		MAP_VIEW_CONTAINER = 'view-left-scroll-menu',
		// MAP_BOTTOM_TOP_MENU = 'bottom-top-menu',
		MAP_BOTTOM_LEFT_MENU = 'bottom-left-menu',
		MAP_BOTTOM_RIGH_MENU = 'bottom-right-menu',
		DISABLE_BTN = 'layui-btn-disabled',
		LEFT_TREE_MENU = '#map-left-menu-resource-tree',
		ADD_LAYER = "addLayer",
		ADD_ITEM = "addItem",
		ADD_DESC = "addDesci",
		SET_OPTIONS = "setOptions",
		LIST_MAP = "listMap",
		gloalConfig = {},
		gloalMap = [],
		$ = layui.jquery,
		element = layui.element,
		util = layui.util,
		form = layui.form,
		L = layui.map,
		laytpl = layui.laytpl,
		slider = layui.slider,
		colorpicker = layui.colorpicker,
		page = layui.laypage;

	// 状态使用变量
	var addLayerBtn = null,
		addLayerForm = null,
		addItemForm = null,
		polylineForm = null,
		pointerForm = null,
		heatForm = null,
		antPathForm = null,
		polylineList = null,
		pointerList = null,
		circleList = null,
		polygonList = null,
		antPointList = null,
		antPathList = null,
		circleForm = null,
		antPathOptionsForm = null,
		shapItemForm = null,
		LEFT_TREE_MENU_OBJ = null,
		antPathDelayText = null,
		antPathWeightText = null,
		antPathDash1Text = null,
		antPathDash2Text = null,
		antPathDelaySilder = null,
		antPathWeightSilder = null,
		antPathDash1Silder = null,
		antPathDash2Silder = null,
		scorllMenu = null,
		scorllMenuPanel = null,
		scrollMenuTitle = null,
		scrollMenuContent = null,
		iconContent = null,
		iconContainer = null, //编辑模式下，用于保存图标弹窗的对象
		iconContainer0 = null, //编辑模式下，锚点的标记用法
		TextNode = { //提示常量
			TIP01: '此操作将会删除该图层下所有的图形，你确定要删除吗?',
			TIP02: '该图层已被隐藏',
			TIP03: '该图层解除隐藏',
			TIP04: '你无法删除一个已被隐藏的点',
			TIP05: '你无法删除一个已被隐藏的多边形',
			TIP06: '该图层已被隐藏，无法执行删除操作。',
			TIP07: '你无法删除一个已被隐藏的图形',
			TIP08: '已经将未被设置隐藏的图层清除',
			TIP09: '已存在相同的资源名',
			TIP10: '将会清空该面板下的所有图层，你确定要删除吗？',
			TIP11: '此动作会清空当前列表里所有的圆形，你确定要删除吗?',
			TIP12: '列表中暂未发现圆形，无法删除',
			TIP13: '此动作会清空当前列表里所有的点，并将他们组成新的图形，你确定要这样做吗?',
			TIP14: '需要三个点才可以绘制成一个图形',
			TIP15: '该多边形已被隐藏',
			TIP16: '你确定要删除该多边形吗?',
			TIP17: '此动作会清空当前列表里所有的多边形，你确定要删除吗?',
			TIP18: '此动作会清空当前列表里所有的点，你确定要删除吗?',
			TIP19: '你确定要删除该点吗?',
			TIP20: '该点已被隐藏',
			TIP21: '该圆已被隐藏',
			TIP22: '你确定要删除该圈吗?',
			TIP23: '你无法删除隐藏的图层',
			TIP24: '添加一个新图层',
			TIP25: '添加一个资源',
			TIP26: '你确定要删除该图层吗?',
			TIP27: '已经获取的地图数据',
			TIP28: '该地图已在视图中加载',
			TIP29: '画点什么再保存吧',
			TIP30: '地图数据.json',
			TIP31: '你需要先加载一个地图模板才能添加一个图层',
			TIP32: '预览模式下，需制定url路径',
			TIP33: '你确定要删除该锚点吗?',
			TIP34: '此动作会清空当前列表里所有的锚点，你确定要删除吗?',
			TIP35: '该蚂蚁点已被隐藏',
			TIP36: '此动作会清空当前列表里所有的蚂蚁点，你确定要删除吗?',
			TIP37: '此动作会清空当前列表里所有的蚂蚁点，并将他们组成蚂蚁线，你确定要这样做吗?',
			TIP38: '需要二个点才可以绘制成一条线',
			TIP39: '该蚂蚁线已经被隐藏',
			TIP40: '你无法删除一个已被隐藏的蚂蚁线',
			TIP41: '直接点击蚂蚁线进行编辑',
			TIP42: '此动作会清空当前列表里所有的蚂蚁线，你确定要删除吗?',
		},
		isEdit = false, //是否是编辑
		isView = false, //是否是预览
		currentPaint = null, //当前是否是多边形的画图模式
		currentShapeForm = {}, //记录当前表单的事件是什么
		currentShapeFormTemp = {}, //临时记录 currentShapeForm的内容是什么
		currentSelectMenuItem = null, //预览模式下，表示当前所选择的菜单是什么
		currentSelectIcon = null, //编辑模式下，所选中的icon是什么。
		currentSelectIcon0 = null, //编辑模式下，锚点模式所确定的是什么图标
		currentAntPath = null, //编辑模式下，当前编辑的是东西是什么
		currentAntPathOptions = null, //编辑模式下，当前编辑的蚂蚁线路径是什么
		activeMap = '', //当前激活的地图id
		activeConfig = {}, //当前激活的地图配置
		markIcon = L.Icon.extend({
			options: {
				iconUrl: './img/util/mark.png',
				iconSize: [20, 20]
			}
		}),
		supportShape = ['polyline', 'polygon', 'circle', 'pointer', 'heat', 'antPath', 'antPoint'],
		dropMapping = { //下拉框键值映射
			"0": "多边形",
			"1": "圆形",
			"2": "锚点",
			"9": "点",
			"3": "热力图",
			"4": "蚂蚁线",
			"8": "蚂蚁点"
		},
		dropMappingValue = {
			"0": "polygon",
			"1": "circle",
			"2": "pointer",
			"9": "polyline",
			"3": "heat",
			"4": "antPath",
			"8": "antPoint",
		}, //内置的稀有度映射，对应的是css的类名，后面可以也许会做成自定义配置
		dropRareMappingValue = {
			"0": {
				name: "普通",
				cln: "layui-bg-lightgreen",
				bln: "layui-border-lightgreens"
			},
			"1": {
				name: "稀有",
				cln: "layui-bg-deepblue",
				bln: "layui-border-deepblue"
			},
			"2": {
				name: "史诗",
				cln: "layui-bg-purple",
				bln: "layui-border-purple"
			},
			"3": {
				name: "传说",
				cln: "layui-bg-snowblue",
				bln: "layui-border-snowblue"
			},
		},
		shapeUtils = { // 对应图形的一些方法
			"0": { //多边形
				modeValue: function(layerId, bodyId) {
					form.val('polyLineMenuAddForm', {
						bodyId: bodyId,
						layerId: layerId
					});
					currentShapeForm = form.val('polyLineMenuAddForm');
				},
				plainFuncWindow: function(flag) {
					if (typeof(flag) == undefined) {
						return;
					}
					if (flag) {
						plainFuncIndex["0"] = layer.open({
							type: 1,
							title: '多边形工具',
							area: ['15%', '75%'],
							offset: 'r',
							shade: 0,
							closeBtn: 0, //不显示关闭按钮
							id: 'polylineFormId',
							btnAlign: 'c',
							moveType: 1,
							resize: false,
							content: $(polylineForm)
						});
						currentPaint = shapeUtils["0"].plainFunc;
					} else {
						layer.close(plainFuncIndex["0"]);
						// 取消掉当前绘画对象
						currentPaint = null;
					}
				},
				plainFunc: function(e) {
					var latlng = e.latlng,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						map = tabMap[activeMap].obj,
						lat = latlng.lat.toFixed(3),
						lng = latlng.lng.toFixed(3),
						id = uuid(),
						polyline = L.marker([lat, lng], {
							icon: new markIcon()
						}).addTo(map);
					// 是否有对这个表单下面的内容是否有赋值
					laytpl(MARK_ITEM_MENU).render({
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: "9"
					}, function(html) {
						polyline.bindPopup(html);
					});
					var tempStruct = null;
					if (leftItemHtmlOperator.isEmptyData(layerId, bodyId)) {
						leftItemHtmlOperator.initData(layerId, bodyId, 'polygon');
					}
					tempStruct = leftItemHtmlOperator.data(layerId, bodyId);
					tempStruct.latlngs.data[id] = [lat, lng];
					tempStruct.latlngs.len += 1;

					// latlngs.data[id] = [lat, lng];
					// latlngs.len += 1;
					laytpl(POLYLINE_MENU_ITEM).render({
						id: id
					}, function(html) {
						polylineList.append(html);
						leftItemHtmlOperator.insertPolyline(layerId, bodyId, id, {
							obj: polyline,
							data: [lat, lng],
							visiable: true
						});
					});
				},
				hideLayer: function(menuBody, menuBodyElement) {
					//关于多边形，由于要存储 点 和 所购成多边形的图形
					//取出点
					var polygons = menuBody.data.polygon,
						polygonsElement = menuBodyElement.data.polygon,
						polyline = menuBody.data.polyline,
						polylineElement = menuBodyElement.data.polyline;
					if (polygons) {
						for (var polygon in polygons) {
							polygonsElement[polygon].remove();
							polygonsElement[polygon] = null;
							polygons[polygon].visiable = false;
						}
						// menuBody.data.polygon = polygons;
					}
					if (polyline) {
						for (var mark in polyline) {
							polylineElement[mark].remove();
							polylineElement[mark] = null;
							polyline[mark].visiable = false;
						}
						// menuBody.data.polyline = polyline;
					}
				},
				showLayer: function(menuBody, menuBodyElement, map) {
					var polygons = menuBody.data.polygon,
						polygonsElement = menuBodyElement.data.polygon,
						polyline = menuBody.data.polyline,
						polylineElement = menuBodyElement.data.polyline;
					if (polygons) {
						for (var polygon in polygons) {
							var pol = polygons[polygon];
							var p = L.polygon(pol.data, {
								color: pol.color
							}).addTo(map).bindPopup("是这个多边形");
							polygonsElement[polygon] = p;
							polygons[polygon].visiable = true;
						}
						// menuBody.data.polygon = polygons;
					}
					if (polyline) {
						for (var mark in polyline) {
							var ma = polyline[mark];
							var m = L.marker(ma.data, {
								icon: new markIcon()
							}).addTo(map).bindPopup("是这个点");
							polylineElement[mark] = m;
							polyline[mark].visiable = true;
						}
						// menuBody.data.polyline = polyline;
					}
					// return menuBody;
				},
				switchMenu: function(layerId, bodyId, flag) {
					var polygonPanelData = leftItemHtmlOperator.elementData(layerId, bodyId),
						polylinePanelData = leftItemHtmlOperator.elementData(layerId, bodyId);

					if (polygonPanelData) {

						var polygonPanels = polygonPanelData.polygonPanel;

						if (flag) {
							for (var polygonP in polygonPanels) {
								polygonPanels[polygonP].show();
							}
						} else {
							for (var polygonP in polygonPanels) {
								polygonPanels[polygonP].hide();
							}
						}
					}
					if (polylinePanelData) {
						var polylinePanels = polylinePanelData.polylinePanel;
						if (flag) {
							for (var polygonL in polylinePanels) {
								polylinePanels[polygonL].show();
							}
						} else {
							for (var polygonL in polylinePanels) {
								polylinePanels[polygonL].hide();
							}
						}
					}
				}
			},
			"4": { // 蚂蚁线
				modeValue: function(layerId, bodyId) {
					form.val('antPathMenuAddForm', {
						bodyId: bodyId,
						layerId: layerId
					});
					currentShapeForm = form.val('antPathMenuAddForm');
				},
				plainFuncWindow: function(flag) {
					if (typeof(flag) == undefined) {
						return;
					}
					if (flag) {
						plainFuncIndex["4"] = layer.open({
							type: 1,
							title: '蚂蚁线工具',
							area: ['300px', '600px'],
							offset: 'r',
							shade: 0,
							closeBtn: 0, //不显示关闭按钮
							id: 'antPathFormId',
							btnAlign: 'c',
							moveType: 1,
							resize: false,
							content: $(antPathForm)
						});
						currentPaint = shapeUtils["4"].plainFunc;
					} else {
						layer.close(plainFuncIndex["4"]);
						currentPaint = null;
					}
				},
				plainFunc: function(e) {
					currentShapeForm = form.val('antPathMenuAddForm');
					var latlng = e.latlng,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						map = tabMap[activeMap].obj,
						lat = latlng.lat.toFixed(3),
						lng = latlng.lng.toFixed(3),
						id = uuid(),
						point = L.marker([lat, lng], {
							icon: new markIcon()
						}).addTo(map);
					laytpl(MARK_ITEM_MENU).render({
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: "8"
					}, function(html) {
						point.bindPopup(html);
					});
					var tempStruct = null;
					if (leftItemHtmlOperator.isEmptyData(layerId, bodyId)) {
						leftItemHtmlOperator.initData(layerId, bodyId, 'antPath');
					}
					tempStruct = leftItemHtmlOperator.data(layerId, bodyId);
					tempStruct.latlngs.data[id] = [lat, lng];
					tempStruct.latlngs.len += 1;
					laytpl(ANTPOINT_ITEM).render({
						id: id
					}, function(html) {
						antPointList.append(html);
						leftItemHtmlOperator.insertAntPoint(layerId, bodyId, id, {
							obj: point,
							data: [lat, lng],
							visiable: true
						});
					});
				},
				hideLayer: function(menuBody, menuBodyElement) {},
				showLayer: function(menuBody, menuBodyElement, map) {},
				switchMenu: function(layerId, bodyId, flag) {
					var antPanelData = leftItemHtmlOperator.elementData(layerId, bodyId);

					if (antPanelData) {

						var antPointPanels = antPanelData.antPointPanel;

						if (flag) {
							for (var antPointPanelP in antPointPanels) {
								antPointPanels[antPointPanelP].show();
							}
						} else {
							for (var polygonP in antPointPanels) {
								antPointPanels[antPointPanelP].hide();
							}
						}
					}
					if (antPanelData) {
						var antPathPanels = antPanelData.antPathPanel;
						if (flag) {
							for (var antPathPanelL in antPathPanels) {
								antPathPanels[antPathPanelL].show();
							}
						} else {
							for (var antPathPanelL in antPathPanels) {
								antPathPanels[antPathPanelL].hide();
							}
						}
					}
				}
			},
			"3": { // 热力图
				modeValue: function(layerId, bodyId) {
					form.val('heatMenuAddForm', {
						bodyId: bodyId,
						layerId: layerId
					});
					currentShapeForm = form.val('heatMenuAddForm');
				},
				plainFuncWindow: function(flag) {
					if (typeof(flag) == undefined) {
						return;
					}
					if (flag) {
						plainFuncIndex["3"] = layer.open({
							type: 1,
							title: '热力图工具',
							area: ['300px', '500px'],
							offset: 'r',
							shade: 0,
							closeBtn: 0, //不显示关闭按钮
							id: 'heatFormId',
							btnAlign: 'c',
							moveType: 1,
							resize: false,
							content: $(heatForm)
						});
						currentPaint = shapeUtils["3"].plainFunc;
					} else {
						layer.close(plainFuncIndex["3"]);
						currentPaint = null;
					}
				},
				plainFunc: function(e) {
					currentShapeForm = form.val('heatMenuAddForm');
					var latlng = e.latlng,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						map = tabMap[activeMap].obj,
						lat = latlng.lat.toFixed(3),
						lng = latlng.lng.toFixed(3),
						id = uuid();
					if (leftItemHtmlOperator.isEmptyData(layerId, bodyId)) {
						leftItemHtmlOperator.initData(layerId, bodyId, 'heat');
					}
					// 是否有对这个表单下面的内容是否有赋值
					leftItemHtmlOperator.insertHeatData(layerId, bodyId, [lat, lng]);
					var heat = null;
					if (leftItemHtmlOperator.checkHeatLayer(layerId, bodyId)) {
						heat = leftItemHtmlOperator.insertHeatLayer(layerId, bodyId, L.heatLayer([e.latlng]).addTo(map));
					} else {
						heat = leftItemHtmlOperator.getHeatLayer(layerId, bodyId);
						heat.setLatLngs(leftItemHtmlOperator.getHeatData(layerId, bodyId));
					}
				},
				hideLayer: function(menuBody, menuBodyElement, clickLayerId, clickId) {
					var heat = leftItemHtmlOperator.getHeatLayer(clickLayerId, clickId);
					heat.setLatLngs([]);
					// leftItemHtmlOperator.setHeatLayerNull(clickLayerId, clickId);
				},
				showLayer: function(menuBody, menuBodyElement, map, clickLayerId, clickId) {
					var heat = leftItemHtmlOperator.getHeatLayer(clickLayerId, clickId);
					heat.setLatLngs(leftItemHtmlOperator.getHeatData(clickLayerId, clickId));
				},
				switchMenu: function(layerId, bodyId, flag) {
					//热力图的切换,不需要ui界面，所有可以为空
				}
			},
			"2": { //锚点
				modeValue: function(layerId, bodyId) {
					form.val('pointerMenuAddForm', {
						bodyId: bodyId,
						layerId: layerId
					});
					currentShapeForm = form.val('pointerMenuAddForm');
				},
				plainFuncWindow: function(flag) {
					if (typeof(flag) == undefined) {
						return;
					}
					if (flag) {
						plainFuncIndex["2"] = layer.open({
							type: 1,
							title: '锚点工具',
							area: ['300px', '500px'],
							offset: 'r',
							shade: 0,
							closeBtn: 0, //不显示关闭按钮
							id: 'pointerFormId',
							btnAlign: 'c',
							moveType: 1,
							resize: false,
							content: $(pointerForm)
						});
						currentPaint = shapeUtils["2"].plainFunc;
					} else {
						layer.close(plainFuncIndex["2"]);
						currentPaint = null;
					}
				},
				plainFunc: function(e) {
					// 刷新一下获得表单值
					currentShapeForm = form.val('pointerMenuAddForm');
					var latlng = e.latlng,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						iurl = currentShapeForm.iurl,
						iconId = currentShapeForm.icon, //icon的id
						map = tabMap[activeMap].obj,
						lat = latlng.lat.toFixed(3),
						lng = latlng.lng.toFixed(3),
						// 锚点也许也是可以自定义的
						id = uuid(),
						icon0 = L.icon({
							iconUrl: iurl,
							iconSize: [40, 40]
						}),
						iconObj = L.marker([lat, lng], {
							icon: icon0
						}).addTo(map);
					// 是否有对这个表单下面的内容是否有赋值
					laytpl(POINTER_ITEM_ITEM).render({
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: "2"
					}, function(html) {
						iconObj.bindPopup(html);
					});
					var tempStruct = null;
					if (leftItemHtmlOperator.isEmptyData(layerId, bodyId)) {
						leftItemHtmlOperator.initData(layerId, bodyId, 'pointer');
					}
					// 锚点暂时不考虑界面
					laytpl(POINTER_MENU_ITEM).render({
						id: id,
						url: iurl
					}, function(html) {
						pointerList.append(html);
						leftItemHtmlOperator.insertPointer(layerId, bodyId, id, {
							obj: iconObj,
							data: [lat, lng],
							iurl: iurl,
							icon: iconId,
							visiable: true
						});
					});

				},
				hideLayer: function(menuBody, menuBodyElement) {
					var pointers = menuBody.data.pointer,
						pointerElement = menuBodyElement.data.pointer;
					if (pointers) {
						for (var pointer in pointers) {
							pointerElement[pointer].remove();
							pointerElement[pointer] = null;
							pointers[pointer].visiable = false;
						}
						// menuBody.data.circle = circles;
					}
				},
				showLayer: function(menuBody, menuBodyElement, map) {
					var pointers = menuBody.data.pointer,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						pointerElement = menuBodyElement.data.pointer;
					if (pointers) {
						for (var pointer in pointers) {
							var poin = pointers[pointer],
								icon0 = L.icon({
									iconUrl: poin.iurl,
									iconSize: [40, 40]
								}),
								iconObj = L.marker(poin.data, {
									icon: icon0
								}).addTo(map);
							laytpl(POINTER_ITEM_ITEM).render({
								layerId: layerId,
								bodyId: bodyId,
								id: pointer,
								type: "2"
							}, function(html) {
								iconObj.bindPopup(html);
							});
							pointerElement[pointer] = iconObj;
							pointers[pointer].visiable = true;
						}
					}
				},
				switchMenu: function(layerId, bodyId, flag) {
					var pointerPanleData = leftItemHtmlOperator.elementData(layerId, bodyId);
					if (pointerPanleData) {
						var pointerPanel = pointerPanleData.pointerPanel;
						if (flag) {

							for (var pointerP in pointerPanel) {
								pointerPanel[pointerP].show();
							}
						} else {
							for (var pointerP in pointerPanel) {
								pointerPanel[pointerP].hide();
							}
						}
					}
				}
			},
			// 圆形
			"1": {
				modeValue: function(layerId, bodyId) {
					form.val('circleMenuAddForm', {
						bodyId: bodyId,
						layerId: layerId
					});
					currentShapeForm = form.val('circleMenuAddForm');
				},
				plainFuncWindow: function(flag) {
					if (typeof(flag) == undefined) {
						return;
					}
					if (flag) {
						plainFuncIndex["1"] = layer.open({
							type: 1,
							title: '圆形工具',
							area: ['15%', '50%'],
							offset: 'r',
							shade: 0,
							closeBtn: 0, //不显示关闭按钮
							id: 'circleFormId',
							btnAlign: 'c',
							moveType: 1,
							resize: false,
							content: $(circleForm)
						});
						currentPaint = shapeUtils["1"].plainFunc;
					} else {
						layer.close(plainFuncIndex["1"]);
						currentPaint = null;
					}
				},
				plainFunc: function(e) {
					// 对于画圆圈，会沿用以前的页面展示的配置
					var latlng = e.latlng,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						map = tabMap[activeMap].obj,
						lat = latlng.lat.toFixed(3),
						lng = latlng.lng.toFixed(3),
						id = uuid(),
						color = currentShapeForm.ccolor,
						crv = currentShapeForm.crv,
						radius = parseInt(crv) * 10000,
						circle = L.circle([lat, lng], {
							radius: radius,
							color: color
						})
						.addTo(map);
					laytpl(SHAP_ITEM_MENU).render({
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: "1"
					}, function(html) {
						circle.bindPopup(html);
					});
					// CIRCLE_MENU_ITEM
					if (leftItemHtmlOperator.isEmptyData(layerId, bodyId)) {
						// 需要初始化
						leftItemHtmlOperator.initData(layerId, bodyId, 'circle');
					}
					laytpl(CIRCLE_MENU_ITEM).render({
						id: id
					}, function(html) {
						circleList.append(html);
						leftItemHtmlOperator.insertCircle(layerId, bodyId, id, {
							obj: circle,
							data: [lat, lng],
							radius: radius,
							color: color,
							visiable: true,
							type: '1'
						});
					});

				},
				hideLayer: function(menuBody, menuBodyElement) {
					//是圆形
					var circles = menuBody.data.circle,
						circleElement = menuBodyElement.data.circle;
					if (circles) {
						for (var circle in circles) {
							circleElement[circle].remove();
							circleElement[circle] = null;
							circles[circle].visiable = false;
						}
						// menuBody.data.circle = circles;
					}
					// return menuBody;
				},
				showLayer: function(menuBody, menuBodyElement, map) {
					//是圆形
					var circles = menuBody.data.circle,
						circleElement = menuBodyElement.data.circle;
					if (circles) {
						for (var circle in circles) {
							var cir = circles[circle];
							var c = L.circle(cir.data, {
									radius: cir.radius,
									color: cir.color
								})
								.addTo(map);
							laytpl(SHAP_ITEM_MENU).render({
								layerId: layerId,
								bodyId: bodyId,
								id: circleId,
								type: "1"
							}, function(html) {
								c.bindPopup(html);
							});
							circleElement[circle] = c;
							circles[circle].visiable = true;
						}
						// menuBody.data.circle = circles;
					}
					// return menuBody;
				},
				switchMenu: function(layerId, bodyId, flag) {
					var circlePanleData = leftItemHtmlOperator.elementData(layerId, bodyId);
					if (circlePanleData) {
						var circlePanles = circlePanleData.circlePanel;
						if (flag) {

							for (var circleP in circlePanles) {
								circlePanles[circleP].show();
							}
						} else {
							for (var circleP in circlePanles) {
								circlePanles[circleP].hide();
							}
						}
					}

				}
			}
		},
		//弹窗的索引
		plainFuncIndex = {},
		baseMap = {}, //数据模型->主要存储数据
		baseElementMap = {}, //元素模型->主要元素地图元素
		leftItemHtmlOperator = { //操作面板内容的对象
			checkResource: function(resourceName) {
				return $.inArray(resourceName, baseMap[activeMap].resource) > 0;
			},
			addResource: function(resourceName) {
				baseMap[activeMap].resource.push(resourceName);
			},
			insertLayerElement: function(mapId, layerId, data) {
				if (!baseElementMap[mapId]) {
					baseElementMap[mapId] = {
						leftItemHtml: {}
					};
				}
				baseElementMap[mapId].leftItemHtml[layerId] = {
					kids: {},
					obj: data.obj,
					bodyObj: data.bodyObj
				}
			},
			insertLayer: function(layerId, data) {
				baseMap[activeMap].leftItemHtml[layerId] = {
					kids: data.kids,
					title: data.title
				};
				baseElementMap[activeMap].leftItemHtml[layerId] = {
					kids: {},
					obj: data.obj,
					bodyObj: data.bodyObj
				}
			},
			getLayerElement: function(layerId) {
				return baseElementMap[activeMap].leftItemHtml[layerId];
			},
			getLayer: function(layerId) {
				return baseMap[activeMap].leftItemHtml[layerId];
			},
			insertBodyElement: function(mapId, layerId, bodyId, data) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId] = {
					obj: data.obj,
					data: {}
				};
			},
			insertBody: function(layerId, bodyId, data) {
				var obj = data.obj;
				delete data.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId] = data;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId] = {
					obj: obj,
					data: {}
				};
			},
			getBodyElement: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId];
			},
			getBody: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId];
			},
			delBody: function(layerId, bodyId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId];
			},
			getDescri: function(layerId, bodyId, id) { // 获得一条描述
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.desci[id];
			},
			insertDescri: function(layerId, bodyId, id, param) { //插入一条描述
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.desci[id] = param;
			},
			checkDataExist: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data != null;
			},
			isEmptyData: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data == null;
			},
			initDataElement: function(mapId, layerId, bodyId, objStruct) {
				var elementStruct = instanceFactory[objStruct]();
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data = elementStruct;
			},
			checkHeatLayer: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heatLayer == null;
			},
			insertHeatLayer: function(layerId, bodyId, heatLayer) {
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heatLayer = heatLayer;
				return heatLayer;
			},
			insertHeatData: function(layerId, bodyId, arr) {
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heat.push(arr);
			},
			getHeatData: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heat;
			},
			getHeatLayer: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heatLayer;
			},
			setHeatLayerNull: function(layerId, bodyId) {
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.heatLayer = null;
			},
			initData: function(layerId, bodyId, objStruct) {
				var dataStruct = instanceFactory[objStruct](),
					elementStruct = instanceFactory[objStruct]();
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data = dataStruct;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data = elementStruct;
			},
			selectShapeItem: function(layerId, bodyId) {
				var obj = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
					checkObj = obj.children(".layui-form-checkbox");
				checkObj.click();
			},
			checkBoxFlag: function(bodyId) {
				return form.val(bodyId).checkState;
			},
			switchCheckBoxState: function(bodyId, switchFlag) {
				form.val(bodyId, {
					checkState: switchFlag
				});
			},
			switchCheckBox: function(bodyId, switchFlag) {
				form.val(bodyId, {
					shape: switchFlag,
					checkState: switchFlag
				});
			},
			unselectShapeItem: function(layerId, bodyId) {
				var obj = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
					checkObj = obj.find(".layui-form-checkbox");
				obj.find("input[name='" + bodyId + "']").prop("checked", false);
				checkObj.removeClass('layui-form-checked');
			},
			shapeMenuBody: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].obj;
			},
			elementData: function(layerId, bodyId) {
				//这边是拿元素的
				if (baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId]) {
					return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data;
				} else {
					return null;
				}
			},
			delData: function(layerId, bodyId) {
				//直接清空
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId];
			},
			data: function(layerId, bodyId) {
				//这边是拿数据
				if (baseMap[activeMap].leftItemHtml[layerId].kids[bodyId]) {
					return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data;
				} else {
					return null;
				}
			},
			getAntPathElement: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id];
			},
			getAntPath: function(layerId, bodyId, id) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id];
			},
			getPolygonElement: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[id];
			},
			getPolygon: function(layerId, bodyId, id) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[id];
			},
			getPolygonPanel: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygonPanel[id];
			},
			getPolylinePanel: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polylinePanel[id];
			},
			getPointers: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer;
			},
			getElementAntPath: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id];
			},
			getAntPaths: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath;
			},
			getPolygons: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon;
			},
			getPolyglines: function(layerId, bodyId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline;
			},
			getPolygonPanels: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygonPanel;
			},
			getAntPathPanels: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPathPanel;
			},
			getAntPathPanel: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPathPanel[id];
			},
			getPolylinePanels: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polylinePanel;
			},
			getPolylineElement: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[id];
			},
			getAntPointElement: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[id];
			},
			getAntPoint: function(layerId, bodyId, id) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[id];
			},
			getPointerElement: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[id];
			},
			getPointerPanel: function(layerId, bodyId, id) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointerPanel[id];
			},
			getPointer: function(layerId, bodyId, id) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[id];
			},
			getPolyline: function(layerId, bodyId, id) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[id];
			},
			insertPolygonElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygonPanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertPolygon: function(layerId, bodyId, id, params) {
				var polygon = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '0';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[id] = polygon;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygonPanel[id] = $("#" + id);
			},
			setAntPathOptions: function(layerId, bodyId, id, options) {
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id].options = options;
			},
			getAntPathOptions: function(layerId, bodyId, id, ) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id].options;
			},
			insertAntPath: function(layerId, bodyId, id, params) {
				var antPath = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '4';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id] = antPath;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPathPanel[id] = $("#" + id);
			},
			insertAntPointElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.antPoint[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.antPointPanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertAntPathElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.antPath[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.antPathPanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertPolylineElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.polyline[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.polylinePanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertPointer: function(layerId, bodyId, id, params) {
				var pointer = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '2';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[id] = pointer;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointerPanel[id] = $("#" + id);
			},
			insertAntPoint: function(layerId, bodyId, id, params) {
				var p = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '8';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[id] = p;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPointPanel[id] = $("#" + id);
			},
			insertPolyline: function(layerId, bodyId, id, params) {
				var polyline = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '0';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[id] = polyline;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polylinePanel[id] = $("#" + id);
			},
			insertPointerElementImport: function(mapId, layerId, bodyId, id, obj) {
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.pointerPanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertPointerElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.pointer[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.pointerPanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertCircleElement: function(mapId, layerId, bodyId, id, obj) {
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.circle[id] = obj;
				var htmlElement = $("#" + id);
				baseElementMap[mapId].leftItemHtml[layerId].kids[bodyId].data.circlePanel[id] = htmlElement;
				htmlElement.hide();
			},
			insertCircle: function(layerId, bodyId, id, params) {
				var circle = params.obj;
				delete params.obj;
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].type = '1';
				baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[id] = params;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[id] = circle;
				baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circlePanel[id] = $("#" + id);
			},
			getCircles: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle;
			},
			getCircleElement: function(layerId, bodyId, circleId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[circleId];
			},
			getCircle: function(layerId, bodyId, circleId) {
				return baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[circleId];
			},
			getCirclePanel: function(layerId, bodyId, circleId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circlePanel[circleId];
			},
			getCirclePanels: function(layerId, bodyId) {
				return baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circlePanel;
			},
			deleteCircle: function(layerId, bodyId, circleId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[circleId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circle[circleId];
			},
			deleteCirclePanel: function(layerId, bodyId, circleId) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.circlePanel[circleId];
			},
			delPolygon: function(layerId, bodyId, polygonId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[polygonId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygon[polygonId];
			},
			delPolygonPanel: function(layerId, bodyId, polygonPanelId) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polygonPanel[polygonPanelId];
			},
			delAntPath: function(layerId, bodyId, id) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPath[id];
			},
			delAntPathPanel: function(layerId, bodyId, id) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPathPanel[id];
			},
			delPointer: function(layerId, bodyId, pointerId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[pointerId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointer[pointerId];
			},
			delPointerPanel: function(layerId, bodyId, pointerPanelId) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.pointerPanel[pointerPanelId];
			},
			delPolyline: function(layerId, bodyId, markId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[markId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polyline[markId];
			},
			delAntPoint: function(layerId, bodyId, markId) {
				delete baseMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[markId];
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPoint[markId];
			},
			delPolylinePanel: function(layerId, bodyId, markPanelId) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.polylinePanel[markPanelId];
			},
			delAntPointPanel: function(layerId, bodyId, markPanelId) {
				delete baseElementMap[activeMap].leftItemHtml[layerId].kids[bodyId].data.antPointPanel[markPanelId];
			},
			switchVisiableLeftMenuShape: function(e) {
				var dataset = e[0].dataset,
					map = tabMap[activeMap].obj,
					clickId = dataset.id,
					clickLayerId = dataset.layerid,
					rt = dataset.type,
					menuBody = leftItemHtmlOperator.getBody(clickLayerId, clickId),
					menuBodyElement = leftItemHtmlOperator.getBodyElement(clickLayerId, clickId),
					tipParam = {
						tips: 1,
						time: 1000
					};
				if (menuBody.data) {
					//隐藏
					if (dataset.visiable == "true") {
						shapeUtils[rt].hideLayer(menuBody, menuBodyElement, clickLayerId, clickId);
						// leftItemHtmlOperator.insertBody(clickLayerId,clickId,);
						// baseMap[activeMap].leftItemHtml[clickLayerId].kids[clickId] = ;
						layer.tips(TextNode.TIP02, e, tipParam);
						e[0].dataset["visiable"] = "false";
						e.css({
							"color": "#1E9FFF"
						});
					} else {
						shapeUtils[rt].showLayer(menuBody, menuBodyElement, map, clickLayerId, clickId);
						// leftItemHtmlOperator.insertBody(clickLayerId,clickId,);
						// baseMap[activeMap].leftItemHtml[clickLayerId].kids[clickId] = ;
						//显示
						layer.tips(TextNode.TIP03, e, tipParam);
						e[0].dataset["visiable"] = "true";
						e.css({
							"color": "black"
						});
					}
				} else {
					//隐藏
					if (dataset.visiable == "true") {
						layer.tips(TextNode.TIP02, e, tipParam);
						e[0].dataset["visiable"] = "false";
						e.css({
							"color": "#1E9FFF"
						});
					} else {
						layer.tips(TextNode.TIP03, e, tipParam);
						e[0].dataset["visiable"] = "true";
						e.css({
							"color": "black"
						});
					}
				}

			},
			showMap: function(mapId) {
				//传入地图id，将右侧菜单进行展示
				if (baseMap[mapId]) {
					var act = tabMap[mapId].act,
						actForm = act.actForm,
						actPaint = act.actPaint;
					if (actForm.type) {
						currentShapeForm = actForm;
						currentPaint = actPaint;
						shapeUtils[actForm.type].plainFuncWindow(true);
						shapeUtils[actForm.type].switchMenu(actForm.layerId, actForm.bodyId, true);
					}
					var leftItems = baseElementMap[mapId].leftItemHtml;
					for (var html in leftItems) {
						leftItems[html].obj.show();
					}
				} else {
					//说明是全新的，需要等待界面初始化
					currentPaint = null;
					currentShapeForm = {};
				}
			},
			hideMap: function(mapId) {
				if (baseMap[mapId]) {
					//传入地图id，将右侧菜单进行展示
					tabMap[mapId].act = {
						actForm: currentShapeForm,
						actPaint: currentPaint
					}
					// #issue I41LM3
					if (currentShapeForm.type) {
						shapeUtils[currentShapeForm.type].plainFuncWindow(false);
						shapeUtils[currentShapeForm.type].switchMenu(currentShapeForm.layerId, currentShapeForm.bodyId, false);
					}
					var leftItems = baseElementMap[mapId].leftItemHtml;
					for (var html in leftItems) {
						leftItems[html].obj.hide();
					}
				}
			},
			setMap: function(mapId, data) {
				baseMap[mapId] = {
					leftItemHtml: data
				};
			},
			getMap: function(mapId) {
				return baseMap[mapId].leftItemHtml;
			},
			encode: function() { //将本地数据解释成web数据
				var webData = {
					id: activeMap,
					cfg: tabMap[activeMap].cfg,
					data: leftItemHtmlOperator.getMap(activeMap),
				};
				return webData;
			},
			decode: function(webData) //将web数据解释成本地数据
			{
				return {};
			}
		}, //删除工具 supportShape=['polygon','circle'],
		leftItemElement = { //界面元素的创建,初始化UI和内容,大前提是对象已经初始化
			polygon: {
				initTemplate: function(mapId, layerId, bodyId, before, after) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						polygon = d.polygon,
						map = tabMap[activeMap].obj;
					//初始化 多边形
					for (var polygonId in polygon) {
						var polygonData = polygon[polygonId],
							p = L.polygon(polygonData.data, {
								color: polygonData.color,
							}).addTo(map);

						//初始化菜单
						if (after) {
							after(layerId, bodyId, polygonId, p);
						}else{
							laytpl(SHAP_ITEM_MENU).render({
								layerId: layerId,
								bodyId: bodyId,
								id: polygonId,
								type: "0"
							}, function(html) {
								
								p.bindPopup(html);
								if (before) {
									before(mapId, layerId, bodyId, polylineId, p);
								}
							});
						}
					}
				},
				initView: function(layerId, bodyId) {
					this.initTemplate(null, layerId, bodyId, null, function(layerId, bodyId, polygonId, p) {
						viewItemElementOperator.addShape2Body(layerId, bodyId, polygonId, p);
					});
				},
				init: function(mapId, layerId, bodyId, param) {
					//param 里面保存了所有的信息
					// 设计到点和多边形的初始化
					var d = param.data,
						polyline = d.polyline,
						polygon = d.polygon,
						map = tabMap[mapId].obj;

					//初始化 点
					for (var polylineId in polyline) {
						var polylineData = polyline[polylineId],
							p = L.marker(polylineData.data, {
								icon: new markIcon()
							}).addTo(map);
						laytpl(MARK_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: polylineId,
							type: "9"
						}, function(html) {
							p.bindPopup(html);
						});
						laytpl(POLYLINE_MENU_ITEM).render({
							id: polylineId
						}, function(html) {
							polylineList.append(html);
							leftItemHtmlOperator.insertPolylineElement(mapId, layerId, bodyId, polylineId, p);
						});
					}

					//初始化 多边形
					for (var polygonId in polygon) {
						var polygonData = polygon[polygonId],
							p = L.polygon(polygonData.data, {
								color: polygonData.color,
							}).addTo(map);

						//初始化菜单
						laytpl(SHAP_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: polygonId,
							type: "0"
						}, function(html) {
							p.bindPopup(html);
						});

						laytpl(POLYGON_MENU_ITEM).render({
							id: polygonId,
						}, function(html) {
							polygonList.append(html);
							// 颜色预留
							leftItemHtmlOperator.insertPolygonElement(mapId, layerId, bodyId, polygonId, p);
						});
					}
				}
			},
			antPath: {
				initTemplate: function(mapId, layerId, bodyId, before, after) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						antPath = d.antPath,
						map = tabMap[activeMap].obj;
					//初始化 多边形
					for (var antPathId in antPath) {
						var antPathData = antPath[antPathId],
							p = new L.Polyline.AntPath(antPathData.data, antPathData.options)
							.addTo(map);

						//初始化菜单
						if (after) {
							after(layerId, bodyId, antPathId, p);
						}else{
							laytpl(ANTPATH_ITEM_MENU).render({
								layerId: layerId,
								bodyId: bodyId,
								id: antPathId,
								type: "4"
							}, function(html) {
								p.bindPopup(html);
								if (before) {
									before(mapId, layerId, bodyId, antPathId, p);
								}
							});
						}
					}
				},
				initView: function(layerId, bodyId) {
					this.initTemplate(null, layerId, bodyId, null, function(layerId, bodyId, antPathId, p) {
						viewItemElementOperator.addShape2Body(layerId, bodyId, antPathId, p);
					});
				},
				init: function(mapId, layerId, bodyId, param) {
					// 设计到点和多边形的初始化
					var d = param.data,
						antPoint = d.antPoint,
						antPath = d.antPath,
						map = tabMap[mapId].obj;

					//初始化 点
					for (var antPointId in antPoint) {
						var antPointData = antPoint[antPointId],
							point = L.marker(polylineData.data, {
								icon: new markIcon()
							}).addTo(map);
						laytpl(MARK_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: antPointId,
							type: "8"
						}, function(html) {
							point.bindPopup(html);
						});
						laytpl(ANTPOINT_ITEM).render({
							id: antPointId
						}, function(html) {
							antPointList.append(html);
							leftItemHtmlOperator.insertAntPointElement(mapId, layerId, bodyId, antPointId, point);
						});
					}

					//初始化 多边形
					for (var antPathId in antPath) {
						var antPathData = antPath[antPathId],
							p = new L.Polyline.AntPath(antPathData.data, antPathData.options)
							.addTo(map);

						//初始化菜单
						laytpl(ANTPATH_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: antPathId,
							type: "4"
						}, function(html) {
							p.bindPopup(html);
						});
						laytpl(ANTPATH_ITEM).render({
							id: antPathId,
						}, function(html) {
							antPathList.append(html);
							// 颜色预留
							leftItemHtmlOperator.insertAntPathElement(mapId, layerId, bodyId, antPathId, p);
						});
					}
				}
			},
			circle: {
				initTemplate: function(mapId, layerId, bodyId, before, after) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						circle = d.circle,
						map = tabMap[activeMap].obj;
					//初始化 多边形
					for (var circleId in circle) {
						var circleData = circles[circleId],
							c = L.circle(circleData.data, {
								radius: circleData.radius,
								color: circleData.color
							}).addTo(map);
						//初始化菜单
						if (after) {
							after(layerId, bodyId, circleId, c);
						}else{
							laytpl(SHAP_ITEM_MENU).render({
								layerId: layerId,
								bodyId: bodyId,
								id: circleId,
								type: "1"
							}, function(html) {
								c.bindPopup(html);
								if (before) {
									before(mapId, layerId, bodyId, circleId, c);
								}
							});	
						}
					}
				},
				initView: function(layerId, bodyId) {
					this.initTemplate(null, layerId, bodyId, null, function(layerId, bodyId, circleId, c) {
						viewItemElementOperator.addShape2Body(layerId, bodyId, circleId, c);
					});
				},
				init: function(mapId, layerId, bodyId, param) {
					this.initTemplate(mapId, layerId, bodyId, function(mapId, layerId, bodyId, circleId, c) {
						leftItemHtmlOperator.insertCircleElement(mapId, layerId, bodyId, circleId, c);
					}, null);
				}
			},
			pointer: {
				initTemplate: function(mapId, layerId, bodyId, before, after) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						pointer = d.pointer,
						map = tabMap[activeMap].obj;
					//初始化 多边形
					for (var pointerId in pointer) {
						var pointerData = pointer[pointerId],
							icon0 = L.icon({
								iconUrl: pointerData.iurl,
								iconSize: [40, 40]
							}),
							iconObj = L.marker(pointerData.data, {
								icon: icon0
							}).addTo(map);
						//初始化菜单
						if (after) {
							after(layerId, bodyId, pointerId, iconObj);
						}else{
							laytpl(POINTER_ITEM_ITEM).render({
								layerId: layerId,
								bodyId: bodyId,
								id: pointerId,
								type: "2"
							}, function(html) {
								iconObj.bindPopup(html);
								if (before) {
									before(mapId, layerId, bodyId, pointerId, iconObj, pointerData);
								}
							});
							
						}
					}
				},
				initView: function(layerId, bodyId) {
					this.initTemplate(null, layerId, bodyId, null, function(layerId, bodyId, pointerId, iconObj) {
						viewItemElementOperator.addShape2Body(layerId, bodyId, pointerId, iconObj);
					});
				},
				init: function(mapId, layerId, bodyId, param) {
					this.initTemplate(mapId, layerId, bodyId, function(mapId, layerId, bodyId, pointerId, iconObj, pointerData) {
						// 锚点暂时不考虑界面
						laytpl(POINTER_MENU_ITEM).render({
							id: pointerId,
							url: pointerData.iurl
						}, function(html) {
							pointerList.append(html);
							leftItemHtmlOperator.insertPointerElement(mapId, layerId, bodyId, pointerId, iconObj);
						});
					}, null);
				}
			},
			heat: {
				initTemplate: function(mapId, layerId, bodyId, before, after) {
					//特殊图形，特殊处理
				},
				initView: function(layerId, bodyId) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						heatData = d.heat,
						map = tabMap[activeMap].obj;
					//初始化 热力图
					if (!viewItemElementOperator.isShapeInit(layerId, bodyId)) {
						viewItemElementOperator.addShape2BodySpec(layerId, bodyId, L.heatLayer(heatData).addTo(map), function(o) {
							o.setLatLngs([]);
						});
					} else {
						viewItemElementOperator.getViewBodyShapes(layerId, bodyId).o.setLatLngs(heatData);
					}
				},
				init: function(mapId, layerId, bodyId, param) {
					var layerHtml = leftItemHtmlOperator.getLayer(layerId),
						kids = layerHtml.kids,
						d = kids[bodyId].data,
						heatData = d.heat,
						map = tabMap[activeMap].obj;
					//初始化 热力图
					var heat = null;
					if (leftItemHtmlOperator.checkHeatLayer(layerId, bodyId)) {
						heat = leftItemHtmlOperator.insertHeatLayer(layerId, bodyId, L.heatLayer(heatData).addTo(map));
					} else {
						heat = leftItemHtmlOperator.getHeatLayer(layerId, bodyId);
						heat.setLatLngs(heatData);
					}
				}
			},
		},
		viewItemElement = {}, //view 模式下的页面缓存。存储格式会很简单，tag->具体图层内容，具体细节从请求数据取
		viewItemElementOperator = {
			initViewLayer: function(layerId) {
				//主要存储两个部分，item 来存储html元素，shape存储生成的图像
				viewItemElement[layerId] = {
					item: {},
					shape: {},
					init: false
				};
			},
			isItemInit: function(layerId) {
				return Object.getOwnPropertyNames(viewItemElement[layerId].item).length > 0;
			},
			isShapeInit: function(layerId) {
				return Object.getOwnPropertyNames(viewItemElement[layerId].shape).length > 0;
			},
			isShapeInit: function(layerId, bodyId) {
				return viewItemElement[layerId].shape[bodyId].o != null;
			},
			initViewBody: function(layerId, bodyId) {
				viewItemElement[layerId].item[bodyId] = [];
				viewItemElement[layerId].shape[bodyId] = [];
			},
			getViewLayer: function(layerId) {
				return viewItemElement[layerId];
			},
			getViewBodyItem: function(layerId, bodyId) {
				return viewItemElement[layerId].item[bodyId];
			},
			getViewBodyShapes: function(layerId, bodyId) {
				return viewItemElement[layerId].shape[bodyId];
			},
			addItem2Body: function(layerId, bodyId, item) {
				viewItemElement[layerId].item[bodyId] = item;
			}, //一些含有特殊的项目,需要设置自己的删除方法
			addShape2BodySpec: function(layerId, bodyId, item, spec) {
				viewItemElement[layerId].shape[bodyId] = {
					o: item,
					spc: spec
				};
			},
			addShape2Body: function(layerId, bodyId, id, shape) {
				viewItemElement[layerId].shape[bodyId][id] = shape;
			},
			hideBodyItem: function(layerId) {
				var bodys = viewItemElement[layerId].item;
				for (var body in bodys) {
					bodys[body].hide();
				}
			},
			showBodyItem: function(layerId) {
				var bodys = viewItemElement[layerId].item;
				for (var body in bodys) {
					bodys[body].show();
				}
			},
			hideBodyShape: function(layerId, bodyId) {
				var shapes = viewItemElement[layerId].shape[bodyId];
				if (shapes.o) {
					shapes.spc(shapes.o);
					return;
				}
				for (var id in shapes) {
					shapes[id].remove();
				}
			},
			showBodyShape: function(layerId, bodyId) {
				var layerHtml = leftItemHtmlOperator.getLayer(layerId),
					kids = layerHtml.kids[bodyId],
					type = kids.type,
					shapeName = dropMappingValue[type];
				leftItemElement[shapeName].initView(layerId, bodyId);
			},
			appendBodyItem: function(layerId) {
				var layerHtml = leftItemHtmlOperator.getLayer(layerId),
					kids = layerHtml.kids;
				for (var bodyId in kids) {
					//这里的kid对应的是bodyId
					var kid = kids[bodyId],
						type = kid.type,
						name = kid.name,
						localRare = dropRareMappingValue[kid.rare];
					laytpl(VIEW_RESOURCE_ITEM).render({
						name: name,
						layerId: layerId,
						bodyId: bodyId,
						rare: localRare.name,
						rareClass: localRare.cln,
						bClass: localRare.bln,
						iurl: kid.iurl
					}, function(html) {
						viewItemElementOperator.initViewBody(layerId, bodyId);
						scrollMenuContent.append(html);
						viewItemElementOperator.addItem2Body(layerId, bodyId, $("#" + bodyId));
					});
				}
			}
		},
		delUtils = {
			polyline: {
				remove: function(id, layerId, bodyId) {
					var targetData = leftItemHtmlOperator.data(layerId, bodyId),
						targetElement = leftItemHtmlOperator.elementData(layerId, bodyId),
						mark = targetData.polyline[id],
						markElement = targetElement.polyline[id],
						markPanel = targetElement.polylinePanel[id],
						datas = targetData.latlngs.data,
						latlng = datas[id];
					if (!mark.visiable) {
						layer.msg(TextNode.TIP04);
						return;
					}
					if (markElement) {
						markElement.remove();
						leftItemHtmlOperator.delPolyline(layerId, bodyId, id);
					}
					if (markPanel) {
						markPanel.remove();
						leftItemHtmlOperator.delPolylinePanel(layerId, bodyId, id);
					}
					if (latlng) {
						targetData = leftItemHtmlOperator.data(layerId, bodyId);
						delete targetData.latlngs.data[id];
						targetData.latlngs.len -= 1;
						return latlng;
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						exsitData = leftItemHtmlOperator.data(layerId, bodyId);
					if (exsitData) {
						var datas = leftItemHtmlOperator.data(layerId, bodyId).latlngs.data;
						for (var o in datas) {
							delUtils.polyline.remove(o, layerId, bodyId);
						}
						exsitData.latlngs.data = {};
						exsitData.latlngs.len = 0;
					}
				},
				uninstall: function() {
					this.clear();
				}
			},
			pointer: {
				remove: function(id, layerId, bodyId) {
					var targetData = leftItemHtmlOperator.data(layerId, bodyId),
						pointerElement = leftItemHtmlOperator.getPointerElement(layerId, bodyId, id),
						pointer = targetData.pointer[id],
						pointerPanel = leftItemHtmlOperator.getPointerPanel(layerId, bodyId, id);
					if (!pointer.visiable) {
						layer.msg(TextNode.TIP04);
						return;
					}
					if (pointerElement) {
						pointerElement.remove();
						leftItemHtmlOperator.delPointer(layerId, bodyId, id);
					}
					if (pointerPanel) {
						pointerPanel.remove();
						leftItemHtmlOperator.delPointerPanel(layerId, bodyId, id);
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						menuBody = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
						visiable = menuBody.find('.layui-icon-menu-fill')[0].dataset.visiable,
						pointers = leftItemHtmlOperator.getPointers(layerId, bodyId);
					//找到内容的状态
					if ("false" == visiable) {
						layer.msg(TextNode.TIP06);
						return;
					} else {
						for (var o in pointers) {
							delUtils.pointer.remove(o, layerId, bodyId);
						}
					}
				},
				uninstall: function() {
					this.clear();
				}
			},
			polygon: {
				remove: function(id, layerId, bodyId) {
					var ploygon = leftItemHtmlOperator.getPolygon(layerId, bodyId, id),
						ploygonElement = leftItemHtmlOperator.getPolygonElement(layerId, bodyId, id),
						ploygonPanel = leftItemHtmlOperator.getPolygonPanel(layerId, bodyId, id);

					if (!ploygon.visiable) {
						layer.msg(TextNode.TIP05);
						return;
					}
					if (ploygonElement) {
						ploygonElement.remove();
						leftItemHtmlOperator.delPolygon(layerId, bodyId, id);
					}
					if (ploygonPanel) {
						ploygonPanel.remove();
						leftItemHtmlOperator.delPolygonPanel(layerId, bodyId, id);
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						menuBody = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
						visiable = menuBody.find('.layui-icon-menu-fill')[0].dataset.visiable,
						polygons = leftItemHtmlOperator.getPolygons(layerId, bodyId);
					//找到内容的状态
					if ("false" == visiable) {
						layer.msg(TextNode.TIP06);
						return;
					} else {
						for (var o in polygons) {
							delUtils.polygon.remove(o, layerId, bodyId);
						}
					}
				},
				uninstall: function() {
					this.clear();
					leftItemHtmlOperator.delData(currentShapeForm.layerId, currentShapeForm.bodyId);
				}
			},
			circle: {
				remove: function(id, layerId, bodyId) {
					var circle = leftItemHtmlOperator.getCircle(layerId, bodyId, id),
						circleElement = leftItemHtmlOperator.getCircleElement(layerId, bodyId, id),
						circlePanel = leftItemHtmlOperator.getCirclePanel(layerId, bodyId, id);
					// 如果这个图形不可见，就意味着被隐藏了，那么就暂时不支持删除
					if (!circle.visiable) {
						layer.msg(TextNode.TIP07);
						return;
					}
					if (circleElement) {
						circleElement.remove();
						leftItemHtmlOperator.deleteCircle(layerId, bodyId, id);
					}
					if (circlePanel) {
						circlePanel.remove();
						leftItemHtmlOperator.deleteCirclePanel(layerId, bodyId, id);
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						menuBody = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
						visiable = menuBody.find('.layui-icon-menu-fill')[0].dataset.visiable,
						circles = leftItemHtmlOperator.getCircles(layerId, bodyId);

					//找到内容的状态
					if ("false" == visiable) {
						layer.msg(TextNode.TIP06);
						return;
					} else {
						for (var c in circles) {
							delUtils.circle.remove(c, layerId, bodyId);
						}
					}
				},
				uninstall: function() {
					this.clear();
					leftItemHtmlOperator.delData(currentShapeForm.layerId, currentShapeForm.bodyId);
				}
			},
			heat: {
				remove: function(id, layerId, bodyId) {
					//由于热力图设计的特殊性，仅仅只用layerId和bodyId已经可以定义全部。
					leftItemHtmlOperator.data(layerId, bodyId).heat = [];
					leftItemHtmlOperator.getHeatLayer(layerId, bodyId).setLatLngs([]);
					// leftItemHtmlOperator.setHeatLayerNull(layerId, bodyId);
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId;
					delUtils.heat.remove(null, layerId, bodyId);
				},
				uninstall: function() {
					this.clear();
					leftItemHtmlOperator.delData(currentShapeForm.layerId, currentShapeForm.bodyId);
				}
			},
			antPoint: {
				remove: function(id, layerId, bodyId) {
					var targetData = leftItemHtmlOperator.data(layerId, bodyId),
						targetElement = leftItemHtmlOperator.elementData(layerId, bodyId),
						mark = targetData.antPoint[id],
						markElement = targetElement.antPoint[id],
						markPanel = targetElement.antPointPanel[id],
						datas = targetData.latlngs.data,
						latlng = datas[id];
					if (!mark.visiable) {
						layer.msg(TextNode.TIP04);
						return;
					}
					if (markElement) {
						markElement.remove();
						leftItemHtmlOperator.delAntPoint(layerId, bodyId, id);
					}
					if (markPanel) {
						markPanel.remove();
						leftItemHtmlOperator.delAntPointPanel(layerId, bodyId, id);
					}
					if (latlng) {
						targetData = leftItemHtmlOperator.data(layerId, bodyId);
						delete targetData.latlngs.data[id];
						targetData.latlngs.len -= 1;
						return latlng;
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						exsitData = leftItemHtmlOperator.data(layerId, bodyId);
					if (exsitData) {
						var datas = leftItemHtmlOperator.data(layerId, bodyId).latlngs.data;
						for (var o in datas) {
							delUtils.antPoint.remove(o, layerId, bodyId);
						}
						exsitData.latlngs.data = {};
						exsitData.latlngs.len = 0;
					}
				},
				uninstall: function() {
					this.clear();
				}
			},
			antPath: {
				remove: function(id, layerId, bodyId) {
					var antPath = leftItemHtmlOperator.getAntPath(layerId, bodyId, id),
						antPathElement = leftItemHtmlOperator.getAntPathElement(layerId, bodyId, id),
						antPathPanel = leftItemHtmlOperator.getAntPathPanel(layerId, bodyId, id);

					if (!antPath.visiable) {
						layer.msg(TextNode.TIP40);
						return;
					}
					if (antPathElement) {
						antPathElement.remove();
						leftItemHtmlOperator.delAntPath(layerId, bodyId, id);
					}
					if (antPathPanel) {
						antPathPanel.remove();
						leftItemHtmlOperator.delAntPathPanel(layerId, bodyId, id);
					}
				},
				clear: function() {
					var layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						menuBody = leftItemHtmlOperator.shapeMenuBody(layerId, bodyId),
						visiable = menuBody.find('.layui-icon-menu-fill')[0].dataset.visiable,
						antPaths = leftItemHtmlOperator.getAntPaths(layerId, bodyId);
					//找到内容的状态
					if ("false" == visiable) {
						layer.msg(TextNode.TIP06);
						return;
					} else {
						for (var o in antPaths) {
							delUtils.antPath.remove(o, layerId, bodyId);
						}
					}
				},
				uninstall: function() {
					this.clear();
					leftItemHtmlOperator.delData(currentShapeForm.layerId, currentShapeForm.bodyId);
				}
			}
		},
		/**
		 * 由于可以同时编辑多个地图，所以这边存储每个tab的实现
		 * map的当前状态,以及对应持有的一些状态，包括目前编辑的是哪个图层，和一些使用状态
		 * 用于在切换tab页的时候可以有效的还原
		 * mapId:{
				obj
				act:一些数据
			}
		 */
		tabMap = {},
		/*
		 多边形的组件，包含两个对象，一个是点的列表，一个是已经连成多边形的图形
		  id:obj
		*/
		//圆形对象
		antPathOptionsFactory = {
			antPath: function() {
				var obj = { //编辑模式下，蚂蚁线默认配置
					paused: false,
					reverse: false,
					delay: 400,
					weight: 5,
					dashArray: [10, 20],
					color: '#0000FF',
					pulseColor: '#FFFFFF'
				}
				return obj;
			}
		},
		instanceFactory = {
			'pointer': function() {
				var obj = {
					pointer: {},
					pointerPanel: {},
					desci: {}, //增加描述
					type: '2'
				};
				return obj;
			},
			'circle': function() {
				var obj = {
					circle: {}, //对应圆形的遮罩
					circlePanel: {}, //对应的圆形的面板
					desci: {}, //增加描述
					type: '1'
				};
				return obj;
			},
			'polygon': function() {
				var obj = {
					polyline: {}, //对应的多边形点的遮罩
					polylinePanel: {}, //对应的多边形点的面板
					polygon: {}, //对应的多边形的遮罩,obj表示地图中的图形实体，data表示包含的数据，是一个数据
					polygonPanel: {}, //对应多边形的面板
					desci: {}, //增加描述
					latlngs: { //暂存的列表数据
						data: {},
						len: 0
					},
					type: '0'
				};
				return obj;
			},
			'heat': function() {
				var obj = {
					heatLayer: null, //热力图层，在第一次初始化后，将会持有
					heat: [], //热力图的数据
					heatPanel: {}, //热力图可能存在的界面
					type: '3'
				}
				return obj;
			},
			'antPath': function() {
				var obj = {
					antPoint: {}, //点
					antPointPanel: {}, //点面板
					antPath: {}, //线
					antPathPanel: {},
					latlngs: { //暂存的列表数据
						data: {},
						len: 0
					},
					type: "4"
				};
				return obj;
			}
		},
		/**
		 * 事件处理
		 */
		eventHandler = {
			'submit(addLayer)': {
				e: form,
				func: function(data) {
					var field = data.field,
						id = uuidParent();
					initMapParam();
					if (leftItemHtmlOperator.checkResource(field.rn)) {
						layer.msg(TextNode.TIP09);
						return false;
					}
					leftItemHtmlOperator.addResource(field.rn);
					var d = {
						title: field.rn,
						id: id, //区别内容的id
						bodyId: id.replace(LAYER, ''),
					};
					laytpl(LEFT_LAYER_ITEM).render(d, function(html) {
						LEFT_TREE_MENU_OBJ.append(html);
						//将对象放在本地
						leftItemHtmlOperator.insertLayer(d.id, {
							obj: $("#" + d.id),
							bodyObj: $("#" + d.bodyId),
							title: d.title,
							kids: {}
						});
					});
					layer.close(plainFuncIndex[ADD_LAYER]);
					addLayerForm.reset();
					return false;
				}
			},
			'submit(addItem)': {
				e: form,
				func: function(data) {
					var field = data.field,
						layerHtml = leftItemHtmlOperator.getLayer(field.layerId),
						layerElement = leftItemHtmlOperator.getLayerElement(field.layerId),
						layerBody = layerElement.bodyObj,
						kids = layerHtml.kids,
						bodyId = uuid(),
						layerId = field.layerId,
						rt = field.rt,
						localRare = dropRareMappingValue[field.rare];
					//取出对应的body容器
					// baseMap[activeMap].leftItemHtml[field.layerId].bodyObj;
					laytpl(LEFT_LAYER_SHAPE_ITEM).render({
						id: bodyId,
						layerId: layerId,
						name: field.rn,
						rt: rt,
						rare: localRare.name,
						rareClass: localRare.cln,
						bClass: localRare.bln,
						icon: field.icon,
						iurl: field.iconUrl,
						type: dropMapping[rt]
					}, function(html) {
						layerBody.append(html);
						//面板和数据挂钩起来
						leftItemHtmlOperator.insertBody(layerId, bodyId, {
							obj: $("#" + bodyId), //面板
							name: field.rn,
							type: rt, //类型
							rare: field.rare,
							icon: field.icon,
							iurl: field.iconUrl,
							data: null //数据
						});
					});
					layer.close(plainFuncIndex[ADD_ITEM]);
					form.render();
					addItemForm.reset();
					destoryIconContainer();
					return false;
				}
			},
			'submit(addDesci)': {
				e: form,
				func: function(data) {
					var field = data.field,
						layerId = field.layerId,
						bodyId = field.bodyId,
						id = field.id;
					leftItemHtmlOperator.insertDescri(layerId, bodyId, id, {
						desName: field.desName,
						desContent: field.desContent
					});
					layer.close(plainFuncIndex[ADD_DESC]);
					form.render();
					shapItemForm.reset();
					return false;
				}
			},
			'checkbox(activeCheck)': {
				e: form,
				func: function(data) {
					//点击编辑的某个资源图层的时候，或者切换他们之间的的时候
					//会决定他们这个图层是否显示，
					// 如果之前编辑的工具栏中有还未编辑完成的内容,将会保存 并且弹窗关闭
					// 打开属于这个资源图层的弹窗
					// 点击的目标的id
					// 获得之前开的是什么资源的窗口
					var dataset = $(data.elem)[0].dataset,
						//在这之前编辑的资源目录
						type = currentShapeForm.type,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId,
						// 点击了新产生的的layerid，clickId这里就是bodyId了
						clickBodyId = dataset.id,
						clickLayerId = dataset.layerid,
						clickType = dataset.type;
					//将曾经打开的图标弹窗都消除掉。
					destoryIconContainer();
					// 同时，这里还涉及数据初始化的问题，包括隐藏显示的图层，和不显示的图层，和切换的对应图层的数据初始化到制定目标列表
					openItemMode(clickType, clickLayerId, clickBodyId);
					if (typeof(layerId) == 'undefined') {
						// 第一次进入的时候，currentShapeForm是没有值得
						shapeUtils[clickType].plainFuncWindow(true);
						leftItemHtmlOperator.switchCheckBoxState(clickBodyId, true);
						shapeUtils[clickType].switchMenu(clickLayerId, clickBodyId, true);
					} else {
						//否则就是有值，我们需要关闭上一个弹出的页面
						//判断一下，点击的是否是自己
						if (!(layerId == clickLayerId && bodyId == clickBodyId)) {
							//如果之前的某个页面已经存在了生成的菜单，需要把之前已经生成的菜单删除掉，
							//然后按照新点击的内容生成菜单，需要根据类型来生成相对应的菜单
							//例如，如果是圆形切换到多边形是不需要进行菜单隐藏，但是是同类型，也就是多边形与多边形就需要
							//如果是同一类型，就直接切换显示就行，没必要关闭之前已经打开的菜单
							shapeUtils[type].switchMenu(layerId, bodyId, false); //关闭上一个菜单
							shapeUtils[clickType].switchMenu(clickLayerId, clickBodyId, true); //打开现在的菜单
							if (type != clickType) {
								shapeUtils[type].plainFuncWindow(false);
								shapeUtils[clickType].plainFuncWindow(true);
							} else {
								if (leftItemHtmlOperator.checkBoxFlag(bodyId) == 'false' &&
									leftItemHtmlOperator.checkBoxFlag(clickBodyId) == 'false') {
									shapeUtils[clickType].plainFuncWindow(true);
								}
							}
							//取消选中
							leftItemHtmlOperator.switchCheckBox(bodyId, false);
							leftItemHtmlOperator.switchCheckBoxState(clickBodyId, true);
						} else {
							shapeUtils[clickType].plainFuncWindow(data.elem.checked);
							//如果点的是自己，那么有可能是想关闭自己
							leftItemHtmlOperator.switchCheckBoxState(clickBodyId, data.elem.checked);
						}

					}
					//edi得到美化后的DOM对象
				}
			},
			'checkbox(antPathCheck)': {
				e: form,
				func: function(data) {
					var dataset = $(data.elem)[0].dataset;
					if ('pause' == dataset.name) {
						if (data.elem.checked) {
							currentAntPath.pause();
						} else {
							currentAntPath.resume();
						}
						currentAntPathOptions.pause = data.elem.checked;
					}
					if ('reverse' == dataset.name) {
						currentAntPathOptions.reverse = data.elem.checked;
						currentAntPath.reverse();
					}
				}
			},
			'tab(map-tab)': {
				e: element,
				func: function(data) {
					var that = this;
					//由于地图是彼此分离的，所有只要右侧菜单能够自如切换就行
					if ('' == activeMap) {
						activeMap = $(that).attr('lay-id');
					}
					leftItemHtmlOperator.hideMap(activeMap);
					activeMap = $(that).attr('lay-id');
					leftItemHtmlOperator.showMap(activeMap);
				}
			}
		}

	/* 编辑页面的页面布局*/
	var BODY = [
			'<div class="layui-row" style="position:absolute;width:100%;height:100%;">',
			'<div class="bottom-left-menu" id="bottom-left-menu" >',
			'</div>',
			'<div class="bottom-right-menu" id="bottom-right-menu" >',
			'</div>',
			'</div>'
		].join(''),
		LEFT_MENU = [
			'<div class="map-left-menu layui-bg-gray">',
			'<div class="layui-btn-group map-left-menu-btn-group">',
			'<button id="addLayer" type="button"  lay-active="addLayer" class="layui-btn layui-btn-normal"><i class="layui-icon layui-icon-add-1" style="margin-right: 1px;"></i></button>',
			'<button id="loadMap" type="button"  lay-active="loadMap" class="layui-btn layui-btn-normal">加载地图</button>',
			'<button id="loadHistory" type="button"  lay-active="loadHistory" class="layui-btn layui-btn-normal">历史数据</button>',
			'</div>',
			'<div class="map-left-menu-resource-panel">',
			'<div id="map-left-menu-resource-tree" class="map-left-menu-resource-tree" ></div>',
			'</div>',
			'</div>'
		].join(''),
		LEFT_LAYER_ITEM = [
			'<div class="left-layer-item" id="{{ d.id }}">',
			'<div class="layui-card">',
			'<div class="layui-card-header">{{ d.title }}',
			'<div class="left-layer-item-menu">',
			'<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary" ><i class="layui-icon layui-icon-addition" data-id="{{ d.id }}" lay-active="addItem" style="font-size: 15px;cursor: pointer;"></i></a> ',
			'<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary" lay-active="clearLayer" data-id="{{ d.id }}">清空图层</a>',
			'<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-primary" ><i class="layui-icon layui-icon-delete" data-id="{{ d.id }}" lay-active="delItem" style="font-size: 15px;cursor: pointer;"></i></a>',
			'</div>',
			'</div>',
			'<div class="layui-card-body" >',
			'<div class="layui-form" lay-filter="LeftLayerItemMenu" action="" id="{{ d.bodyId }}">',
			'</div>',
			'</div>',
			'</div>',
			'</div>',
		].join(''),
		LEFT_LAYER_SHAPE_ITEM = [ //图形的单位
			'<form class="layui-form" id="{{ d.id }}" lay-filter="{{ d.id }}" style="height: 50px;border:1px solid #1E9FFF;border-radius:5px;margin-bottom: 5px;" >',
			'<div  class="left-layer-shape-item" data-id="{{ d.id }}">',
			'<input name="checkState" type="hidden" value="false"/>',
			'<input type="checkbox" lay-filter="activeCheck" lay-skin="primary" data-id="{{ d.id }}" data-type="{{ d.rt }}" data-layerId="{{ d.layerId }}"  name="shape" title="{{ d.name }}">',
			'<div class="left-layer-shape-item-menu">',
			'<i class="layui-icon layui-icon-menu-fill" data-id="{{ d.id }}" data-type="{{ d.rt }}" data-layerId="{{ d.layerId }}" data-visiable="true" lay-active="switchVisiableLeftMenuShape" ></i>',
			'<i class="layui-icon layui-icon-delete" data-id="{{ d.id }}" data-type="{{ d.rt }}"  data-layerId="{{ d.layerId }}" lay-active="delLeftLayerShapeItem" ></i>',
			'</div></div>',
			'<div class="left-layer-shape-ext">',
			'<img src="{{ d.iurl }}" class="layui-form-item-img1" />',
			'<span class="layui-badge {{ d.rareClass }}" style="margin-left:15px;" >{{ d.rare }}</span>',
			'<span class="layui-badge layui-bg-blue" style="margin-left:5px;">{{ d.type }}</span>',
			'</div>',
			'</form>'
		].join(''),
		LEFT_MENU_ADD_LAYER_FORM = [
			'<form id="left-menu-layer-add-form" class="layui-form layui-form-pane" action="" style="display:none;width:90%;margin:20px auto;" >',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">图层名称</label>',
			'<div class="layui-input-block">',
			'<input type="text" name="rn" autocomplete="off" lay-verify="required" placeholder="图层名称" class="layui-input">',
			'</div>',
			'</div>',
			'<div class="layui-form-item" style="text-align: center;">',
			'<button class="layui-btn" lay-submit="" lay-filter="addLayer" >添加</button>',
			'<a href="javascript:;" class="layui-btn layui-btn-primary" lay-active="closeAll">关闭</a>',
			'</div>',
			'</form>'
		].join(''),
		LEFT_MENU_ADD_FORM = [
			'<form id="left-menu-add-form" class="layui-form layui-form-pane" action="" lay-filter="leftMenuAddForm" style="display:none;width:90%;margin:20px auto;" >',
			'<div class="layui-form-item">',
			'<input type="hidden" name="layerId" >',
			'<label class="layui-form-label">资源名称</label>',
			'<div class="layui-input-block">',
			'<input type="text" name="rn" autocomplete="off" lay-verify="required" placeholder="资源名称" class="layui-input">',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">资源类型</label>',
			'<div class="layui-input-block">',
			'<select name="rt" lay-filter="rt" lay-verify="required">',
			'<option value="2" selected="" >锚点(Point)</option>',
			'<option value="0">多边形(Polygon)</option>',
			'<option value="3">热力图(Heat)</option>',
			'<option value="4">蚂蚁线(AntPath)</option>',
			'<option value="1">圆(Circle)</option>',
			'</select>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">资源稀有度</label>',
			'<div class="layui-input-block">',
			'<select name="rare" lay-filter="rare" lay-verify="required">',
			'<option value="0" selected="" >普通</option>',
			'<option value="1">稀有</option>',
			'<option value="2">史诗</option>',
			'<option value="3">传说</option>',
			'</select>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">资源图标</label>',
			'<input type="hidden" name="icon" value="default" />',
			'<input type="hidden" name="iconUrl" value="./img/material.png" />',
			'<div class="layui-input-block">',
			'<img class="layui-input-img" src="./img/material.png">',
			'<a href="javascript:;" class="layui-btn" style="padding:0 5px;" lay-active="selectImg">选择图标</a>',
			'</div>',
			'</div>',
			'<div class="layui-form-item" style="text-align: center;">',
			'<button class="layui-btn" lay-submit="" lay-filter="addItem" >添加</button>',
			'<a href="javascript:;" class="layui-btn layui-btn-primary" lay-active="closeAll">关闭</a>',
			'</div>',
			'</form>'
		].join(''),
		SELECT_IMG = [
			'<div class="layui-form-select-img">',
			'<span class="layui-layer-setwin" lay-active="closeSelectImg" ><a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;"></a></span>',
			'<form action="" class="layui-form  layui-form-pane" style="height: 50px;border-bottom: 1px solid #F0F0F0;" >',
			'<div class="layui-form-item" style="position:relative;width:90%;top:6px;">',
			'<label class="layui-form-label">图标搜索</label>',
			'<div class="layui-input-block">',
			'<input type="text" name="rn" maxLength="20" autocomplete="off" placeholder="请输入图标名称" class="layui-input">',
			'</div>',
			'</div>',
			'</form>',
			'<div class="layui-form-icon-content">',
			'<div class="layui-form-icon-container">',
			'<div id="layui-form-icon-context" class="layui-form-icon-context">',
			'</div>',
			'<div id="layui-form-page" class="layui-form-page"></div>',
			'</div>',
			'</div>',
			'</div>'
		].join(''),
		SELECT_ICON = [
			'<div class="layui-form-select-img0">',
			'<span class="layui-layer-setwin" lay-active="closeSelectImg" ><a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;"></a></span>',
			'<form action="" class="layui-form  layui-form-pane" style="height: 50px;border-bottom: 1px solid #F0F0F0;" >',
			'<div class="layui-form-item" style="position:relative;width:90%;top:6px;">',
			'<label class="layui-form-label">图标搜索</label>',
			'<div class="layui-input-block">',
			'<input type="text" name="rn" maxLength="20" autocomplete="off" placeholder="请输入图标名称" class="layui-input">',
			'</div>',
			'</div>',
			'</form>',
			'<div class="layui-form-icon-content0">',
			'<div class="layui-form-icon-container">',
			'<div id="layui-form-icon-context0" class="layui-form-icon-context">',
			'</div>',
			'<div id="layui-form-page" class="layui-form-page"></div>',
			'</div>',
			'</div>',
			'</div>'
		].join(''),
		RIGHT_MENU = [
			'<div class="map-right-menu" >',
			'<div class="layui-tab" style="padding:0px;margin:0px;height:100%;background:white;" lay-filter="map-tab">',
			'<ul class="layui-tab-title" >',
			'</ul>',
			'<div class="layui-tab-content" style="height:94.7%;padding:0px;">',
			'</div>',
			'</div>',
			'</div>'
		].join(''),
		POLYLINE_MENU = [
			'<form id="polyline-menu-add-form" class="layui-form layui-form-pane" lay-filter="polyLineMenuAddForm" action="" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" value="0" name="type">',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">点列表</label>',
			'</div>',
			'<div class="layui-form-item">',
			'<div id="polyline-menu-list" class="polyline-menu"></div>',
			'</div>',
			'<div class="layui-form-item">',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="connectPolygon" class="layui-btn layui-btn-sm">连成多边形</button>',
			'<button type="button" lay-active="clearPolyline" class="layui-btn layui-btn-sm layui-btn-danger">清空列表</button>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">多边形列表</label>',
			'</div>',
			'<div class="layui-form-item">',
			'<div id="polygon-menu-list" class="polyline-menu"></div>',
			'</div>',
			'<div class="layui-form-item">',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="clearPolygon" class="layui-btn layui-btn-sm layui-btn-danger">清空列表</button>',
			'</div>',
			'</div>',
			'</form>'
		].join(''),
		ANTPATH_MENU = [
			'<form id="antPath-menu-add-form" class="layui-form layui-form-pane" lay-filter="antPathMenuAddForm" action="" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" value="4" name="type">',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">蚂蚁点</label>',
			'</div>',
			'<div class="layui-form-item">',
			'<div id="ant-point-menu-list" class="antPoint-menu"></div>',
			'</div>',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="connectAntPath" class="layui-btn layui-btn-sm ">连成线</button>',
			'<button type="button" lay-active="clearAntPoint" class="layui-btn layui-btn-sm layui-btn-danger">清空所有点</button>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">蚂蚁路径</label>',
			'</div>',
			'<div class="layui-form-item">',
			'<div id="ant-path-menu-list" class="antPath-menu"></div>',
			'</div>',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="clearAntPath" class="layui-btn layui-btn-sm layui-btn-danger">清空所有线</button>',
			'</div>',
			'</form>'
		].join(''),
		ANTPOINT_ITEM = [
			'<div class="ant-point-menu-item" lay-active="antPointHit"  id="{{ d.id }}" data-id="{{ d.id }}">点</div>'
		].join(''),
		ANTPATH_ITEM = [
			'<div class="ant-path-menu-item"  lay-active="antPathHit" id="{{ d.id }}" data-id="{{ d.id }}">路径</div>'
		].join(''),
		HEAT_MENU = [
			'<form id="heat-menu-add-form" class="layui-form layui-form-pane" lay-filter="heatMenuAddForm" action="" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" value="3" name="type">',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="redrawHeat" class="layui-btn layui-btn-sm layui-btn-danger">重画</button>',
			'</div>',
			'</div>',
			'</form>'
		].join(''),
		POINTER_MENU = [
			'<form id="pointer-menu-add-form" class="layui-form layui-form-pane" lay-filter="pointerMenuAddForm" action="" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" value="2" name="type">',
			'<input type="hidden" value="default" name="icon">',
			'<input type="hidden" value="./img/material.png" name="iurl">',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" >锚点Icon</label>',
			'<img class="layui-input-img" src="./img/material.png">',
			'<a href="javascript:;" style="padding:0 5px;" class="layui-btn" lay-active="setIcon">选择图标</a>',
			'</div>',
			'<div id="pointer-menu-list" class="polyline-menu"></div>',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="clearPointer" class="layui-btn layui-btn-sm layui-btn-danger">清空列表</button>',
			'</div>',
			'</form>'
		].join(''),
		POINTER_MENU_ITEM = [
			'<div class="pointer-menu-item" id="{{ d.id }}" data-id="{{ d.id }}" lay-active="pointerHit" >',
			'<img class="layui-input-pointer-img" src="{{ d.url }}" />',
			'<div class="layui-input-pointer-close" ><i class="layui-icon layui-icon-close" data-id="{{ d.id }}" lay-active="delPointer" style="font-size: 15px;cursor: pointer;"></i></div>',
			'</div>'
		].join(''),
		POLYLINE_MENU_ITEM = [
			'<div class="polyline-menu-item" id="{{ d.id }}" data-id="{{ d.id }}" lay-active="polylineHit" >',
			'点',
			'<div style="float: right;cursor:pointer;"><i class="layui-icon layui-icon-delete" data-id="{{ d.id }}" lay-active="delPolyline" style="font-size: 15px;cursor: pointer;"></i></div>',
			'</div>'
		].join(''),
		POLYGON_MENU_ITEM = [
			'<div class="polyline-menu-item" id="{{ d.id }}" data-id="{{ d.id }}" lay-active="polygonHit" >',
			'多边形',
			'<div style="float: right;cursor:pointer;"><i class="layui-icon layui-icon-delete" data-id="{{ d.id }}" lay-active="delPolygon" style="font-size: 15px;cursor: pointer;"></i></div>',
			'</div>'
		].join(''),
		CIRCLE_MENU = [
			'<form id="circle-menu-add-form" class="layui-form layui-form-pane" lay-filter="circleMenuAddForm" action="" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" value="1" name="type">',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">圆圈颜色</label>',
			'<div class="layui-input-block">',
			'<div id="circleColor" ></div>',
			'<input type="hidden" name="ccolor" value="#1E9FFF">',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">圆圈半径</label>',
			'</div>',
			'<div class="layui-form-item">',
			'<div id="circleRadiusSlider" style="width:90%;"></div>',
			'<input type="hidden"  name="crv" value="10">',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" style="width:100%;">圆列表</label>',
			'<div class="layui-form-item">',
			'<div id="circle-menu-list" class="circle-menu"></div>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<div class="layui-btn-group">',
			'<button type="button" lay-active="delAllCircle" class="layui-btn layui-btn-sm layui-btn-danger">清空列表</button>',
			'</div>',
			'</div>',
			'</form>'
		].join(''),
		CIRCLE_MENU_ITEM = [
			'<div class="circle-menu-item" id="{{ d.id }}" data-id="{{ d.id }}" lay-active="circleHit" >',
			'圆',
			'<div style="float: right;cursor:pointer;">',
			'<i class="layui-icon layui-icon-delete" data-id="{{ d.id }}" lay-active="delCircle" style="font-size: 15px;cursor: pointer;"></i></div>',
			'</div>'
		].join(''),
		ANTPATH_ITEM_MENU = [
			'<ul class="shap-item-ul" data-layer="{{d.layerId}}" data-body="{{d.bodyId}}" data-id="{{d.id}}" data-type="{{d.type}}" >',
			'<li lay-active="menuOption">配置</li>',
			'<li lay-active="menuDescri">添加描述</li>',
			'<li lay-active="menuDel">删除</li>',
			'</ul>'
		].join(''),
		SHAP_ITEM_MENU = [ //图形弹出的菜单
			'<ul class="shap-item-ul" data-layer="{{d.layerId}}" data-body="{{d.bodyId}}" data-id="{{d.id}}" data-type="{{d.type}}" >',
			'<li lay-active="menuDescri">添加描述</li>',
			'<li lay-active="menuDel">删除</li>',
			'</ul>'
		].join(''),
		POINTER_ITEM_ITEM = [
			'<ul class="shap-item-ul" data-layer="{{d.layerId}}" data-body="{{d.bodyId}}" data-id="{{d.id}}" data-type="{{d.type}}" >',
			'<li>锚点菜单</li>',
			'<li lay-active="menuDel">删除</li>',
			'</ul>'
		].join(''),
		MARK_ITEM_MENU = [
			'<ul class="shap-item-ul" data-layer="{{d.layerId}}" data-body="{{d.bodyId}}" data-id="{{d.id}}" data-type="{{d.type}}" >',
			'<li lay-active="menuDel">删除</li>',
			'</ul>'
		].join(''),
		ANTPATH_ITEM_MENU_OPTION = [
			'<form id="shap-item-antPath-form" class="layui-form layui-form-pane" lay-filter="antPathOptionsForm" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" name="id">',
			'<input type="hidden" name="type">',
			'<div class="layui-form-item">',
			'<input type="checkbox" lay-filter="antPathCheck" data-name="pause" name="pause" title="停止动画" lay-skin="primary" >',
			'<input type="checkbox" lay-filter="antPathCheck" data-name="reverse" name="reverse" title="动画反向" lay-skin="primary"> ',
			'<a class="layui-btn" lay-active="antPathOptionReset" >重置</a>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathDelayText" style="width:160px;">流速(600)</label>',
			'<div class="layui-input-block">',
			'<div id="antPathDelay" class="ant-path-slider"></div>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathWeightText" style="width:160px;">线宽(5)</label>',
			'<div class="layui-input-block">',
			'<div id="antPathWeight" class="ant-path-slider"></div>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathDash1Text" style="width:160px;">道路变长(10)</label>',
			'<div class="layui-input-block">',
			'<div id="antPathDash1" class="ant-path-slider"></div>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathDash2Text" style="width:160px;">动画变长(20)</label>',
			'<div class="layui-input-block">',
			'<div id="antPathDash2" class="ant-path-slider" ></div>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathStreetColorText" style="width:160px;">道路颜色</label>',
			'<div class="layui-input-block">',
			'<div id="antPathStreetColor" ></div>',
			'<input type="hidden" name="streetColor" value="#1E9FFF">',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<label class="layui-form-label" id="antPathAnimateColorText" style="width:160px;">动画颜色</label>',
			'<div class="layui-input-block">',
			'<div id="antPathAnimateColor" ></div>',
			'<input type="hidden" name="animaColor" value="#1E9FFF">',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<a class="layui-btn" lay-active="closeAntPathOption" >关闭</a>',
			'</div>',
			'</form>'
		].join(''),
		SHAP_ITEM_VIEW_FORM = [ //图形信息的编辑表单
			'<form id="shap-item-desc-form" class="layui-form layui-form-pane" lay-filter="shapItemViewForm" style="display:none;width:90%;margin:15px auto;" >',
			'<input type="hidden" name="bodyId">',
			'<input type="hidden" name="layerId">',
			'<input type="hidden" name="id">',
			'<input type="hidden" name="type">',
			'<div class="layui-form-item">',
			'<label class="layui-form-label">标题</label>',
			'<div class="layui-input-block">',
			'<input type="text" name="desName" autocomplete="off" lay-verify="required" placeholder="资源名称" class="layui-input">',
			'</div>',
			'</div>',
			'<div class="layui-form-item layui-form-text">',
			'<label class="layui-form-label">描述</label>',
			'<div class="layui-input-block">',
			'<textarea  name="desContent" placeholder="为这个资源添加描述" class="layui-textarea"></textarea>',
			'</div>',
			'</div>',
			'<div class="layui-form-item">',
			'<button class="layui-btn" lay-submit="" lay-filter="addDesci">添加描述</button>',
			'</div>',
			'</form>'
		].join(''),
		MAP_LIST_VIEW = [
			'{{# layui.each(d,function(index,item){ }}',
			'<div class="map-list-content" lay-active="startLoadMap" data-id="{{item.id}}" data-index="{{index}}"><div class="map-list-center">{{ item.name }}</div>',
			'</div>',
			'{{#  }); }}'
		].join(''),
		ICON_ITEM = [
			'<div data-id="{{ d.id }}" data-url="{{ d.url }}" lay-active="selectIcon" class="layui-form-icon-item">',
			'<img class="layui-form-icon-item-img" src="{{ d.url }}" />',
			'<span class="layui-form-icon-item-span" >{{ d.name }}</span>',
			'</div>'
		].join(''),
		ICON_ITEM0 = [
			'<div data-id="{{ d.id }}" data-url="{{ d.url }}" lay-active="selectIcon0" class="layui-form-icon-item">',
			'<img class="layui-form-icon-item-img" src="{{ d.url }}" />',
			'<span class="layui-form-icon-item-span" >{{ d.name }}</span>',
			'</div>'
		].join('');

	/* 预览页面的页面布局*/
	var VIEW_LEFT_SCROLL_MENU = [
			'<div class="view-left-scroll-menu" id="view-left-scroll-menu" >',
			'<div class="view-left-scroll-top-menu">',
			'<div class="view-left-scroll-arrow"><i lay-active="scrollArrow"  class="layui-icon layui-icon-shrink-right" ></i></div>',
			'</div>',
			'<div class="view-left-scroll-bottom-menu">',
			'<div id="view-left-scroll-layer" class="view-left-scroll-layer" >',
			'<div id="view-left-scroll-layer-panel" class="view-left-scroll-layer-panel">',
			'</div>',
			'</div>',
			'<div class="view-left-scroll-content">',
			'<div class="view-left-scroll-search">',
			'<form class="layui-form" action="" style="height:50px;">',
			'<div class="layui-form-item" style="position:absolute;top:7px;width:355px;">',
			'<label class="layui-form-label"><i  class="layui-icon layui-icon-search" ></i></label>',
			'<div class="layui-input-block">',
			'<input type="text" name="search" placeholder="请输入你希望查找的资源名" class="layui-input">',
			'</div>',
			'</div>',
			'</form>',
			'</div>',
			'<div class="view-left-scroll-context">',
			'<fieldset class="layui-elem-field layui-border-cyan"  style="position: absolute;width:99%;">',
			'<legend id="layui-field-title" >资源列表</legend>',
			'<div id="layui-field-content" class="layui-field-box">',

			'</div>',
			'</fieldset>',
			'</div>',
			'</div>',
			'</div>',
			'</div>',
			'<div id="pop"></div>'
		].join(''),
		VIEW_RESOURCE_TAG = [
			'<div class="{{ d.class }}" data-id="{{ d.id }}" lay-active="selectLayer" >{{ d.name }}</div>',
		].join(''),
		VIEW_RESOURCE_ITEM = [
			'<form id="{{ d.bodyId }}" class="layui-form layui-form-item-single" action="" >',
			'<div class="layui-form-item layui-form-item-set {{ d.bClass }}" >',
			'<div class="layui-form-item-input layui-input-block " >',
			'<input type="checkbox" data-layerId="{{ d.layerId }}" data-bodyId="{{ d.bodyId }}"  name="rs"  lay-filter="showResource" title="{{ d.name }}">',
			'<span class="layui-badge {{ d.rareClass }} layui-badge-level">{{ d.rare }}</span>',
			'<img src="{{ d.iurl }}" class="layui-form-item-img" />',
			'</div>',
			'</div>',
			'</form>'
		].join('');

	var mapUI = function() {
		this.v = '0.9.2';
	};

	function currentPolyline() {
		var arr = [],
			layerId = currentShapeForm.layerId,
			bodyId = currentShapeForm.bodyId,
			// datas = latlngs.data,
			datas = leftItemHtmlOperator.data(layerId, bodyId).latlngs.data;
		for (var o in datas) {
			var position = datas[o];
			if (position) {
				arr.push(position);
			}
		}
		return arr;
	}

	function uuid() {
		var temp_url = URL.createObjectURL(new Blob());
		var uuid = temp_url.toString();
		URL.revokeObjectURL(temp_url);
		var tempIds = (uuid.substr(uuid.lastIndexOf("/") + 1)).split('-');
		return tempIds.join('').substr(0, 6);
	}

	function isLayerId(id) {
		id += "";
		return id.indexOf(LAYER) != -1;
	}

	function uuidParent() {
		return LAYER + uuid();
	}

	/**检查参数
	 * @param {Object} map
	 * @param {Object} config
	 */
	function checkParam(config) {}

	function isNotEmpty(obj) {
		return obj != null;
	}

	function generateUI(config) {
		var container = config.container,
			containerQuery = $(container);
		if (MODEL_VIEW === config.mode) {
			// 预览模式
			appendViewUI(containerQuery);
			reqRender(config, containerQuery);
			registerViewEvent();
			isView = true;
		} else if (MODEL_EDIT === config.mode) {
			isEdit = true;
			containerQuery.addClass(MAP_CONTAINER_CLASS_NAME);
			appendEditUI(containerQuery);
			registerEditEvent();
		}
		htmlRender();
	}

	function reqRender(config, container) {
		var url = config.url || '';
		if ('' == url) {
			layer.msg(TextNode.TIP32);
			return false;
		}
		//请求地图数据
		$.ajax({
			url: url,
			type: "GET",
			dataType: "json",
			success: function(e) {
				doRender(e, container);
			}
		});
	}

	function doRender(data, container) {
		//获得对应的mapid
		var mapId = data.id,
			mapCfg = data.cfg,
			mapData = data.data;
		// 目前在预览模式下，只可以加载一种已经编辑好的地图
		tabMap[mapCfg.id] = {
			obj: null,
			cfg: mapCfg,
			act: {
				actForm: null, //当前正在编辑的表单
				actPaint: null //正在使用的绘画方法
			}
		}
		activeMap = mapId;
		var map = tabMap[mapId].obj = L.map('pop', mapCfg.opt).setView(mapCfg.view, mapCfg.zoom);
		L.tileLayer(mapCfg.url, {
			tileSize: 512,
			noWrap: true
		}).addTo(map);
		// map.on('click', editMap);
		//开始创建这个地图
		//数据部分可以直接设置，但是界面部分需要根据基础数据来重新创建
		leftItemHtmlOperator.setMap(mapId, mapData);
		var baseData = leftItemHtmlOperator.getMap(mapId),
			layerBodyMap = {}; // layerId -> type,bodyId
		var first = true,
			className = 'view-left-scroll-layer-item',
			selectCalssName = 'view-left-scroll-layer-item-this';
		for (var layerId in baseData) {
			var dd = baseData[layerId],
				d = {
					title: dd.title,
					id: layerId, //区别内容的id
					bodyId: layerId.replace(LAYER, ''),
				},
				cn = className;
			if (first) {
				cn = selectCalssName;
				scrollMenuTitle.text(d.title);
			}
			laytpl(VIEW_RESOURCE_TAG).render({
				id: d.id,
				name: d.title,
				class: cn
			}, function(html) {
				scorllMenuPanel.append(html);
				viewItemElementOperator.initViewLayer(d.id);
				if (first) {
					currentSelectMenuItem = $("." + cn);

				}
			});
			if (first) {
				viewItemElementOperator.appendBodyItem(d.id);
				first = false;
			}
			form.render();
		}

	}

	/**将配置参数设置到对应的表单里
		颜色暂时不知道如何设置
	 * @param {Object} options
	 */
	function updateAntPath(options) {
		antPathDelaySilder.setValue(options.delay);
		antPathWeightSilder.setValue(options.weight);
		antPathDash1Silder.setValue(options.dashArray[0]);
		antPathDash2Silder.setValue(options.dashArray[1]);
		form.val('antPathOptionsForm', {
			pause: options.pause,
			reverse: options.reverse
		});
	}

	/**
	 * 将蚂蚁线设置回默认值
	 * @param {Object} obj
	 */
	function resetAntPath(obj) {
		var defaultOptions = antPathOptionsFactory.antPath();
		obj.setStyle(defaultOptions);
		currentAntPathOptions = defaultOptions;
		antPathDelaySilder.setValue(400);
		antPathWeightSilder.setValue(5);
		antPathDash1Silder.setValue(10);
		antPathDash2Silder.setValue(20);
		form.val('antPathOptionsForm', {
			pause: false,
			reverse: false
		});
	}

	function htmlRender() {
		element.render();
		form.render();
		antPathDelayText = $("#antPathDelayText");
		antPathWeightText = $("#antPathWeightText");
		antPathDash1Text = $("#antPathDash1Text");
		antPathDash2Text = $("#antPathDash2Text");
		slider.render({
			elem: '#circleRadiusSlider',
			min: 10,
			max: 90,
			step: 10, //步长
			showstep: true, //开启间隔点
			change: function(value) {
				// $('#test-slider-tips1').html('当前数值：'+ value);
				form.val('circleMenuAddForm', {
					crv: value
				});
				currentShapeForm = form.val('circleMenuAddForm');
				layer.tips('圆圈半径调整为：' + value, this.elem, {
					tips: 1,
					time: 500
				});
			}
		});
		antPathDelaySilder = slider.render({
			elem: '#antPathDelay',
			min: 1,
			max: 800,
			step: 1, //步长,
			value: 400,
			change: function(value) {
				antPathDelayText.text('流速(' + value + ')');
				currentAntPath.setStyle({
					delay: value
				});
				currentAntPathOptions.delay = value;
			}
		});
		antPathWeightSilder = slider.render({
			elem: '#antPathWeight',
			min: 1,
			max: 20,
			step: 1, //步长,
			value: 5,
			change: function(value) {
				antPathWeightText.text('线宽(' + value + ')');
				currentAntPath.setStyle({
					weight: value
				});
				currentAntPathOptions.weight = value;
			}
		});
		antPathDash1Silder = slider.render({
			elem: '#antPathDash1',
			min: 1,
			max: 100,
			step: 1, //步长,
			value: 10, //开启间隔点,
			change: function(value) {
				antPathDash1Text.text('道路变长(' + value + ')');
				currentAntPath.setStyle({
					dashArray: [value, currentAntPath.options.dashArray[1]]
				});
				currentAntPathOptions.dashArray = [value, currentAntPath.options.dashArray[1]];
			}
		});
		antPathDash2Silder = slider.render({
			elem: '#antPathDash2',
			min: 1,
			max: 100,
			step: 1, //步长,
			value: 20, //开启间隔点,
			change: function(value) {
				antPathDash2Text.text('动画变长(' + value + ')');
				currentAntPath.setStyle({
					dashArray: [currentAntPath.options.dashArray[0], value]
				});
				currentAntPathOptions.dashArray = [currentAntPath.options.dashArray[0], value];
			}
		});
		colorpicker.render({
			elem: '#circleColor', //绑定元素,
			color: '#1E9FFF',
			change: function(color) { //颜色改变的回调
				form.val('circleMenuAddForm', {
					ccolor: color
				});
				currentShapeForm = form.val('circleMenuAddForm');
				layer.tips('选择了：' + color, this.elem, {
					tips: 1,
					time: 500
				});
			}
		});
		colorpicker.render({
			elem: '#antPathStreetColor', //绑定元素
			color: '#0000FF',
			change: function(color) { //颜色改变的回调
				currentAntPath.setStyle({
					color: color
				});
				currentAntPathOptions.color = color;
			}
		});
		colorpicker.render({
			elem: '#antPathAnimateColor', //绑定元素,
			color: '#FFFFFF',
			change: function(color) { //颜色改变的回调
				currentAntPath.setStyle({
					pulseColor: color
				});
				currentAntPathOptions.pulseColor = color;
			}
		});
	}

	/**
	 * 编辑地图的方法
	 * @param {Object} e 
	 */
	function editMap(e) {
		if (isEdit) {
			if (currentPaint) {
				currentPaint(e);
			}
		}
	}
	/**
	 * 开启某个模式
	 * @param {Object} rn
	 * @param {Object} id
	 */
	function openItemMode(rn, layerId, bodyId) {
		setItemModeValue(rn, layerId, bodyId);
		currentPaint = shapeUtils[rn].plainFunc;
	}
	/**
	 * 设置默认值
	 * @param {Object} rt
	 * @param {Object} id
	 */
	function setItemModeValue(rt, layerId, bodyId) {
		shapeUtils[rt].modeValue(layerId, bodyId);
	}

	/**删除方法体
	 * @param {Object} layerId
	 * @param {Object} bodyId
	 * @return 返回的false表示删除的不是当前正在编辑的图层体
	 */
	function delBody(layerId, bodyId, type) {
		//除了界面，还有包括layerid下面的所有内容，也就是body的内容
		var body = leftItemHtmlOperator.getBody(layerId, bodyId),
			bodyElement = leftItemHtmlOperator.getBodyElement(layerId, bodyId),
			panelObj = bodyElement.obj,
			data = body.data,
			flag = false,
			tempBody = ''; //是否也删除了当前正在选中的对象
		//将复选取消，关闭菜单
		if (currentShapeFormTemp.all) {
			tempBody = currentShapeFormTemp.bodyId;
		} else {
			tempBody = currentShapeForm.bodyId;
			currentShapeFormTemp = currentShapeForm;
		}
		if (tempBody == bodyId) {
			leftItemHtmlOperator.switchCheckBox(bodyId, false);
			shapeUtils[type].plainFuncWindow(false);
			flag = true;
		}
		for (var shape in supportShape) {
			// 所删除的是否是当前的编辑选中的对象
			currentShapeForm = {
				bodyId: bodyId,
				layerId: layerId,
				type: type
			}
			var propertyName = supportShape[shape];
			if (data && data.hasOwnProperty(propertyName)) {
				// 多边形需要额外判断
				delUtils[propertyName].uninstall();
			}
		}
		//到这里意味着所有的图形和ui都已经删除，可以直接将这个熟悉给删除掉
		panelObj.remove();
		leftItemHtmlOperator.delBody(layerId, bodyId);
		if (!flag) {
			currentShapeForm = currentShapeFormTemp;
		}
		return flag
	}

	/**
	 * 清空下方的所有图层
	 * @param {Object} e
	 */
	function clearLayer(e) {
		var layerId = e[0].dataset.id,
			layerObj = leftItemHtmlOperator.getLayer(layerId),
			layerElement = leftItemHtmlOperator.getLayerElement(layerId),
			kids = layerElement.kids,
			currentShapeFormTemp = currentShapeForm,
			flag = false;
		currentShapeFormTemp.all = true; //表示是从清空方法里面进来的
		for (var kid in kids) {
			var set = kids[kid].obj.find('.layui-icon-menu-fill')[0].dataset;
			if ('false' == set.visiable) {
				continue;
			}
			flag = delBody(layerId, kid, set.type);
		}
		currentShapeFormTemp.all = false;
		if (flag) {
			//表示当前对象已经删除，当前已经没有编辑的对象
			currentShapeForm = {}; //直接设置为空
		} else {
			//否则表示当前编辑的对象还没有删除，将之前存储的临时值赋值回去
			currentShapeForm = currentShapeFormTemp;
		}
		layer.msg(TextNode.TIP08);
	}


	/**
	 * 初始化准备
	 */
	function initMapParam() {
		if (!baseMap[activeMap]) {
			baseMap[activeMap] = {};
			baseElementMap[activeMap] = {};
		}
		if (!baseMap[activeMap].resource) {
			baseMap[activeMap].resource = [];
		}
		if (!baseMap[activeMap].leftItemHtml) {
			baseMap[activeMap].leftItemHtml = {};
			baseElementMap[activeMap].leftItemHtml = {};
		}
	}


	function scrollFunc(e) {
		e = e || window.event;
		if (e.wheelDelta) { //IE/Opera/Chrome  
			//自定义事件：编写具体的实现逻辑  
			mouseScroll(e);
		} else if (e.detail) { //Firefox  
			//自定义事件：编写具体的实现逻辑  
			mouseScroll(e);
		}
	}

	function mouseScroll(e) {
		// 这里会做成判断的，超过了某个长度才会开启滑动
		var target = e.target,
			deltaY = e.deltaY,
			offset = scorllMenuPanel.offset(),
			mile = offset.top + deltaY / 10;
		scorllMenuPanel.offset({
			top: mile
		});
		// 	console.log(mile);
		// scorllMenuPanel.animate({top: mile+'px'}, "fast");
	}

	/**
	 * @param {Object} elem切换菜单
	 */
	function switchMenu(elem) {
		currentSelectMenuItem.removeClass("view-left-scroll-layer-item-this");
		currentSelectMenuItem.addClass("view-left-scroll-layer-item");
		currentSelectMenuItem = elem;
		currentSelectMenuItem.addClass("view-left-scroll-layer-item-this");
		currentSelectMenuItem.removeClass("view-left-scroll-layer-item");
	}
	/**
	 * view 模式下切换页面
	 */
	function switchMenuItem(targetLayerId) {
		var oldLayerId = currentSelectMenuItem[0].dataset.id,
			targetLayerId,
			layerHtml = leftItemHtmlOperator.getLayer(targetLayerId),
			kids = layerHtml.kids;
		// 如果这个图层有被初始化，那就直接展示，否则就先初始化
		if (!viewItemElementOperator.isItemInit(targetLayerId)) {
			viewItemElementOperator.appendBodyItem(targetLayerId);
		}
		scrollMenuTitle.text(layerHtml.title);
		viewItemElementOperator.showBodyItem(targetLayerId);
		viewItemElementOperator.hideBodyItem(oldLayerId);
	}

	/**
	 * 注册预览界面事件
	 */
	function registerViewEvent() {
		if (scorllMenu.addEventListener) {
			scorllMenu.addEventListener('DOMMouseScroll', scrollFunc, false);
		} //W3C  
		scorllMenu.onmousewheel = scorllMenu.onmousewheel = scrollFunc; //IE/Opera/Chrome
		form.on('checkbox(showResource)', function(data) {
			var dataset = data.elem.dataset,
				layerId = dataset.layerid,
				bodyId = dataset.bodyid;
			if (this.checked) {
				viewItemElementOperator.showBodyShape(layerId, bodyId);
			} else {
				viewItemElementOperator.hideBodyShape(layerId, bodyId);
			}
		});
		util.event('lay-active', {
			selectLayer: function(e) {
				var elem = $(e[0]),
					target = elem[0];
				switchMenuItem(target.dataset.id);
				switchMenu(elem);
				form.render();
				return false;
			},
			scrollArrow: function(e) {
				var arrow = $(e[0]),
					menu = $("#" + MAP_VIEW_CONTAINER);
				if (arrow.hasClass('h')) {
					arrow.removeClass('h');
					arrow.removeClass('layui-icon-spread-left');
					arrow.addClass('layui-icon-shrink-right');
					menu.animate({
						left: '0px'
					}, "fast");
				} else {
					arrow.removeClass('layui-icon-shrink-right');
					arrow.addClass('h');
					arrow.addClass('layui-icon-spread-left');
					menu.animate({
						left: '-400px'
					}, "fast");
				}
				return false;
			}
		});
	}

	/**
	 * 注册编辑界面事件
	 */
	function registerEditEvent() {
		for (var event in eventHandler) {
			var o = eventHandler[event];
			o.e.on(event, o.func);
		}
		util.event('lay-active', {
			closeSelectImg: function(e) {
				if (iconContainer) {
					iconContainer.hide();
				}
				if (iconContainer0) {
					iconContainer0.hide();
				}
				return false;
			},
			selectIcon: function(e) {
				var set = e[0].dataset,
					jq = $(e[0]);
				if (currentSelectIcon) {
					currentSelectIcon.removeClass('layui-form-icon-item-this');
					currentSelectIcon.addClass('layui-form-icon-item');
				}
				currentSelectIcon = jq;
				currentSelectIcon.removeClass('layui-form-icon-item');
				currentSelectIcon.addClass('layui-form-icon-item-this');
				//为表单替换所选择的内容
				form.val('leftMenuAddForm', {
					icon: set.id,
					iconUrl: set.url
				});
				$(addItemForm).find(".layui-input-img").attr("src", set.url);
				return false;
			},
			selectIcon0: function(e) {
				var set = e[0].dataset,
					jq = $(e[0]);
				if (currentSelectIcon0) {
					currentSelectIcon0.removeClass('layui-form-icon-item-this');
					currentSelectIcon0.addClass('layui-form-icon-item');
				}
				currentSelectIcon0 = jq;
				currentSelectIcon0.removeClass('layui-form-icon-item');
				currentSelectIcon0.addClass('layui-form-icon-item-this');
				//为表单替换所选择的内容
				form.val('pointerMenuAddForm', {
					icon: set.id,
					iurl: set.url
				});
				$(pointerForm).find(".layui-input-img").attr("src", set.url);
				return false;
			},
			setIcon: function(e) {
				// iconContainer0
				//pointerFormId
				if (!iconContainer0) {
					$("#pointerFormId").parent().prepend(SELECT_ICON);
					iconContainer0 = $(".layui-form-select-img0");
				}
				iconContainer0.show();
				var iconContent = $("#layui-form-icon-context0"),
					pageCfg = {
						limit: 9,
						index: 1
					};
				$.ajax({
					url: "./json/iconCount.json",
					type: "GET",
					data: {
						limit: pageCfg.limit,
						index: pageCfg.curr
					},
					dataType: "json",
					success: function(e) {
						if (e) {
							// 获取第一页的数据
							page.render({
								elem: 'layui-form-page',
								count: e.count,
								limit: pageCfg.limit,
								groups: 1,
								jump: function(obj, first) {
									// 请求数据
									// console.log(obj);
									$.ajax({
										url: "./json/icon.json",
										type: "GET",
										data: {
											limit: obj.limit,
											index: obj.curr
										},
										dataType: "json",
										success: function(e) {
											iconContent.empty();
											var data = e.data;
											for (var d in data) {
												laytpl(ICON_ITEM0).render(data[d], function(icon) {
													iconContent.append(icon);
												});
											}
											// console.log(e);
										}
									});

								}
							});
						}

					}
				});
				return false;
			},
			selectImg: function(e) {
				if (!iconContainer) {
					$("#LAY_layuipro2").parent().prepend(SELECT_IMG);
					iconContainer = $(".layui-form-select-img");
				}
				iconContainer.show();
				var iconContent = $("#layui-form-icon-context"),
					pageCfg = {
						limit: 9,
						index: 1
					};
				$.ajax({
					url: "./json/iconCount.json",
					type: "GET",
					data: {
						limit: pageCfg.limit,
						index: pageCfg.curr
					},
					dataType: "json",
					success: function(e) {
						if (e) {
							// 获取第一页的数据
							page.render({
								elem: 'layui-form-page',
								count: e.count,
								limit: pageCfg.limit,
								groups: 1,
								jump: function(obj, first) {
									// 请求数据
									// console.log(obj);
									$.ajax({
										url: "./json/icon.json",
										type: "GET",
										data: {
											limit: obj.limit,
											index: obj.curr
										},
										dataType: "json",
										success: function(e) {
											iconContent.empty();
											var data = e.data;
											for (var d in data) {
												laytpl(ICON_ITEM).render(data[d], function(icon) {
													iconContent.append(icon);
												});
											}
											// console.log(e);
										}
									});

								}
							});
						}

					}
				});
				// iconContent.empty();
				// 有个请求的动作

				return false;
			},
			loadHistory: function(e) {
				var index = layer.load();
				$.ajax({
					url: "./json/mapData1.json",
					type: "GET",
					dataType: "json",
					success: function(e) {
						importData(e);
						layer.close(index);
					}
				});
				return false;
			},
			startLoadMap: function(e) {
				var dataset = e[0].dataset;
				listMap(dataset);
				return false;
			},
			clearLayer: function(e) {
				layer.confirm(TextNode.TIP10, function(index) {
					clearLayer(e);
					layer.close(index);
				});
				return false;
			},
			closeAntPathOption: function(e) {
				layer.close(plainFuncIndex[SET_OPTIONS]);
				return false;
			},
			antPathOptionReset: function(e) {
				var dataSet = form.val('antPathOptionsForm'),
					id = dataSet.id,
					layerId = dataSet.layerId,
					bodyId = dataSet.bodyId,
					type = dataSet.type;
				//将变量暂时设置到全局变量中
				resetAntPath(leftItemHtmlOperator.getElementAntPath(layerId, bodyId, id));
				return false;
			},
			menuOption: function(e) {
				var dataSet = e[0].parentElement.dataset,
					id = dataSet.id,
					layerId = dataSet.layer,
					bodyId = dataSet.body,
					type = dataSet.type;
				form.val('antPathOptionsForm', {
					layerId: layerId,
					bodyId: bodyId,
					type: type,
					id: id
				});
				//将变量暂时设置到全局变量中
				currentAntPath = leftItemHtmlOperator.getElementAntPath(layerId, bodyId, id);
				currentAntPathOptions = leftItemHtmlOperator.getAntPathOptions(layerId, bodyId, id);
				updateAntPath(currentAntPathOptions);
				plainFuncIndex[SET_OPTIONS] = layer.open({
					type: 1,
					title: '配置',
					area: ['350px', '500px'],
					shade: 0.2,
					id: 'setOptionsId',
					btnAlign: 'c',
					moveType: 1,
					content: $(antPathOptionsForm)
				});
				return false;
			},
			menuDescri: function(e) {
				var dataSet = e[0].parentElement.dataset,
					id = dataSet.id,
					layerId = dataSet.layer,
					bodyId = dataSet.body,
					type = dataSet.type,
					desc = leftItemHtmlOperator.getDescri(layerId, bodyId, id),
					parma = {};
				if (desc) {
					parma = {
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: type,
						desName: desc.desName,
						desContent: desc.desContent
					}
				} else {
					parma = {
						layerId: layerId,
						bodyId: bodyId,
						id: id,
						type: type
					}
				}
				//进行赋值
				form.val('shapItemViewForm', parma);
				plainFuncIndex[ADD_DESC] = layer.open({
					type: 1,
					title: '描述',
					area: ['300px', '350px'],
					shade: 0.2,
					id: 'LAY_layuipro5',
					btnAlign: 'c',
					moveType: 1,
					content: $(shapItemForm)
				});
				return false;
			},
			menuDel: function(e) {
				var dataSet = e[0].parentElement.dataset,
					id = dataSet.id,
					layerId = dataSet.layer,
					bodyId = dataSet.body,
					type = dataSet.type;
				layer.confirm('你确定要删除该' + dropMapping[type] + '吗?', function(index) {
					delUtils[dropMappingValue[type]].remove(id, layerId, bodyId);
					layer.close(index);
				});
				return false;
			},
			delAllCircle: function(e) {
				//是否需要删除
				if (circleList.children().length > 0) {
					layer.confirm(TextNode.TIP11, function(index) {
						delUtils.circle.clear();
						layer.close(index);
					});
				} else {
					layer.msg(TextNode.TIP12);
				}
				return false;
			},
			redrawHeat: function(e) {
				var layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					heatLayer = leftItemHtmlOperator.getHeatLayer(layerId, bodyId);
				// heatLayer.redraw();
				// heatLayer.setLatLngs([[]]);
				delUtils.heat.remove(null, layerId, bodyId);
				return false;
			},
			connectAntPath: function(e) {
				// 蚂蚁点和普通点的性质一样
				var latlngs = currentPolyline();
				if (latlngs.length > 1) {
					layer.confirm(TextNode.TIP37, function(index) {
						var layerId = currentShapeForm.layerId,
							bodyId = currentShapeForm.bodyId,
							id = uuid(),
							options = antPathOptionsFactory.antPath();
						//将所有的数据，挂在到对应的多边形中
						delUtils.antPoint.clear();
						var antPath = new L.Polyline.AntPath(latlngs, options).addTo(tabMap[activeMap].obj);;
						//初始化菜单
						laytpl(ANTPATH_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: id,
							type: "4"
						}, function(html) {
							antPath.bindPopup(html);
						});

						laytpl(ANTPATH_ITEM).render({
							id: id,
						}, function(html) {
							antPathList.append(html);
							// 颜色预留
							leftItemHtmlOperator.insertAntPath(layerId, bodyId, id, {
								obj: antPath,
								data: latlngs,
								visiable: true,
								options: options,
								type: '4'
							});
						});
						layer.close(index);
					});
				} else {
					layer.msg(TextNode.TIP38);
					return false;
				}
				return false;
			},
			connectPolygon: function(e) {
				var latlngs = currentPolyline();
				if (latlngs.length > 2) {
					layer.confirm(TextNode.TIP13, function(index) {
						var layerId = currentShapeForm.layerId,
							bodyId = currentShapeForm.bodyId,
							id = uuid();
						//将所有的数据，挂在到对应的多边形中
						delUtils.polyline.clear();
						var polygon = L.polygon(latlngs, {
							color: '#1E9FFF',
						}).addTo(tabMap[activeMap].obj);
						//初始化菜单
						laytpl(SHAP_ITEM_MENU).render({
							layerId: layerId,
							bodyId: bodyId,
							id: id,
							type: "0"
						}, function(html) {
							polygon.bindPopup(html);
						});

						laytpl(POLYGON_MENU_ITEM).render({
							id: id,
						}, function(html) {
							polygonList.append(html);
							// 颜色预留
							leftItemHtmlOperator.insertPolygon(layerId, bodyId, id, {
								obj: polygon,
								data: latlngs,
								visiable: true,
								color: '#1E9FFF',
								type: '0'
							});
						});
						layer.close(index);
					});
				} else {
					layer.msg(TextNode.TIP14);
					return false;
				}
				return false;
			},
			antPathHit: function(e) {
				layer.msg(TextNode.TIP41);
				return false;
			},
			polygonHit: function(e) {
				var id = e[0].dataset.id,
					layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					polygonElement = leftItemHtmlOperator.getPolygonElement(layerId, bodyId, id),
					polygon = leftItemHtmlOperator.getPolygon(layerId, bodyId, id);
				if (polygon.visiable) {
					polygonElement.togglePopup();
				} else {
					layer.msg(TextNode.TIP15);
				}
				return false;
			},
			delPolygon: function(e) {
				layer.confirm(TextNode.TIP16, function(index) {
					var id = e[0].dataset.id,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId;
					delUtils.polygon.remove(id, layerId, bodyId);
					layer.close(index);
				});
				return false;
			},
			clearAntPath: function(e) {
				layer.confirm(TextNode.TIP36, function(index) {
					delUtils.antPath.clear();
					layer.close(index);
				});
				return false;
			},
			clearAntPoint: function(e) {
				layer.confirm(TextNode.TIP36, function(index) {
					delUtils.antPoint.clear();
					layer.close(index);
				});
				return false;
			},
			clearPointer: function(e) {
				layer.confirm(TextNode.TIP34, function(index) {
					delUtils.pointer.clear();
					layer.close(index);
				});
				return false;
			},
			clearPolygon: function(e) {
				layer.confirm(TextNode.TIP17, function(index) {
					delUtils.polygon.clear();
					layer.close(index);
				});
				return false;
			},
			clearPolyline: function(e) {
				layer.confirm(TextNode.TIP18, function(index) {
					delUtils.polyline.clear();
					layer.close(index);
				});
				return false;
			},
			delPointer: function(e) {
				layer.confirm(TextNode.TIP33, function(index) {
					var id = e[0].dataset.id,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId;
					delUtils.pointer.remove(id, layerId, bodyId);
					layer.close(index);
				});
				return false;
			},
			delPolyline: function(e) {
				layer.confirm(TextNode.TIP19, function(index) {
					var id = e[0].dataset.id,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId;
					delUtils.polyline.remove(id, layerId, bodyId);
					layer.close(index);
				});
				return false;
			},
			pointerHit: function(e) {
				var id = e[0].dataset.id,
					layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					pointerElement = leftItemHtmlOperator.getPointerElement(layerId, bodyId, id),
					pointer = leftItemHtmlOperator.getPointer(layerId, bodyId, id);
				if (pointer.visiable) {
					pointerElement.togglePopup();
				} else {
					layer.msg(TextNode.TIP20);
				}
			},
			antPointHit: function(e) {
				var id = e[0].dataset.id,
					layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					antPointElement = leftItemHtmlOperator.getAntPointElement(layerId, bodyId, id),
					antPoint = leftItemHtmlOperator.getAntPoint(layerId, bodyId, id);
				if (antPoint.visiable) {
					antPointElement.togglePopup();
				} else {
					layer.msg(TextNode.TIP35);
				}
				return false;
			},
			polylineHit: function(e) {
				var id = e[0].dataset.id,
					layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					polylineElement = leftItemHtmlOperator.getPolylineElement(layerId, bodyId, id),
					polyline = leftItemHtmlOperator.getPolyline(layerId, bodyId, id);
				if (polyline.visiable) {
					polylineElement.togglePopup();
				} else {
					layer.msg(TextNode.TIP20);
				}
				return false;
			},
			circleHit: function(e) {
				var id = e[0].dataset.id,
					layerId = currentShapeForm.layerId,
					bodyId = currentShapeForm.bodyId,
					circleElement = leftItemHtmlOperator.getCircleElement(layerId, bodyId, id),
					circle = leftItemHtmlOperator.getCircle(layerId, bodyId, id);
				if (circle.visiable) {
					circleElement.togglePopup()
				} else {
					layer.msg(TextNode.TIP21);
				}
				return false;
			},
			delCircle: function(e) {
				layer.confirm(TextNode.TIP22, function(index) {
					var id = e[0].dataset.id,
						layerId = currentShapeForm.layerId,
						bodyId = currentShapeForm.bodyId;
					delUtils.circle.remove(id, layerId, bodyId);
					layer.close(index);
				});
				return false;
			},
			switchVisiableLeftMenuShape: function(e) {
				leftItemHtmlOperator.switchVisiableLeftMenuShape(e);
			},
			delLeftLayerShapeItem: function(e) {
				var dataset = e[0].dataset,
					layerId = dataset.layerid,
					bodyId = dataset.id,
					type = dataset.type,
					visiable = e.siblings()[0].dataset.visiable;
				if ('false' == visiable) {
					layer.msg(TextNode.TIP23);
					return;
				}
				layer.confirm(TextNode.TIP01, function(index) {
					delBody(layerId, bodyId, type);
					layer.close(index);
				});
				return false;
			},
			addLayer: function(e) {
				//如果是禁用状态就不可使用
				if ($(e[0]).hasClass('layui-btn-disabled')) {
					layer.msg(TextNode.TIP31);
					return false;
				}
				plainFuncIndex[ADD_LAYER] = layer.open({
					type: 1,
					title: TextNode.TIP24,
					area: ['300px', '200px'],
					shade: 0.2,
					id: 'LAY_layuipro',
					btnAlign: 'c',
					moveType: 1,
					content: $(addLayerForm)
				});
			},
			addItem: function(e) {
				var id = e[0].dataset.id;
				// 赋值给表单
				form.val('leftMenuAddForm', {
					layerId: id
				});
				plainFuncIndex[ADD_ITEM] = layer.open({
					type: 1,
					title: TextNode.TIP25,
					area: ['300px', '500px'],
					shade: 0.2,
					id: 'LAY_layuipro2',
					btnAlign: 'c',
					moveType: 1,
					cancel: function(index, layero) {
						destoryIconContainer();
						layer.close(index);
						return false;
					},
					content: $(addItemForm)
				});
			},
			delItem: function(e) {
				// console.log(e);
				layer.confirm(TextNode.TIP26, function(index) {
					//do something
					var id = e[0].dataset.id;
					var obj = baseMap[activeMap].leftItemHtml[id].obj;
					obj.remove();
					delete baseMap[activeMap].leftItemHtml[id];
					//相关联的数据也要删除 todo
					layer.close(index);
				});
				return false;
			},
			loadMap: function(e) {
				//这里正常需要拉取接口，读取已经上传的地图列表
				// 模拟拉取地图数据
				$.ajax({
					url: gloalConfig.mapUrl,
					type: "GET",
					dataType: "json",
					success: function(e) {
						appendMapData(e.data);
						laytpl(MAP_LIST_VIEW).render(gloalMap, function(html) {
							plainFuncIndex[LIST_MAP] = layer.open({
								type: 1,
								title: TextNode.TIP27,
								area: ['300px', '400px'],
								shade: 0.2,
								id: 'MAP_list',
								btnAlign: 'c',
								moveType: 1,
								content: html
							});
						});
					},
					statusCode: {
						404: function() {
							alert("数据请求 404");
						}
					},
				});
				return false;
			},
			closeAll: function(e) {
				layer.closeAll();
				destoryIconContainer();
				return false;
			}
		});
	}

	/**
	 * 添加数据到全局地图资源中
	 * @param {Object} data
	 */
	function appendMapData(data) {
		var count = gloalMap.length;
		for (var o in data) {
			gloalMap.push(data[o]);
		}
	}

	/**
	 * 懒加载更多的地图数据
	 * @param {Object} data 地图数据
	 */
	function listMap(data) {
		var d = activeConfig = gloalMap[data.index];
		if (tabMap[d.id]) {
			layer.msg(TextNode.TIP28);
			return;
		} else {
			tabMap[d.id] = {
				obj: null,
				cfg: d,
				act: {
					actForm: null, //当前正在编辑的表单
					actPaint: null //正在使用的绘画方法
				}
			}
		}
		element.tabAdd('map-tab', {
			title: d.name,
			content: '<div id="map' + d.id + '" style="cursor:default;"></div>',
			id: d.id //实际使用一般是规定好的id，这里以时间戳模拟下
		});
		element.tabChange('map-tab', d.id);
		var map = tabMap[d.id].obj = L.map('map' + d.id, d.opt).setView(d.view, d.zoom);
		L.tileLayer(d.url, {
			tileSize: 512,
			noWrap: true
		}).addTo(map);
		map.on('click', editMap);
		// 放开禁用
		addLayerBtn.removeClass(DISABLE_BTN);
		layer.close(plainFuncIndex[LIST_MAP]);
	}

	function appendViewUI(container) {
		// 算是一切预览的起点
		container.append(VIEW_LEFT_SCROLL_MENU);
		var cssStyle = {
			"position": "absolute",
			"width": "100%",
			"height": "100%"
		};
		container.css(cssStyle);
		$("#pop").css(cssStyle);
		var viewContainer = $("#" + MAP_VIEW_CONTAINER);
		scorllMenu = document.getElementById("view-left-scroll-layer"),
			scorllMenuPanel = $(scorllMenu).find('#view-left-scroll-layer-panel'),
			scrollMenuTitle = $("#layui-field-title"),
			scrollMenuContent = $("#layui-field-content");
	}

	function appendEditUI(container) {
		container.css({
			"position": "absolute",
			"width": "100%",
			"height": "100%"
		});
		var htmlQueue = [
			BODY,
			LEFT_MENU_ADD_LAYER_FORM,
			LEFT_MENU_ADD_FORM,
			SHAP_ITEM_VIEW_FORM,
			ANTPATH_ITEM_MENU_OPTION,
			POLYLINE_MENU,
			CIRCLE_MENU,
			POINTER_MENU,
			HEAT_MENU,
			ANTPATH_MENU
		];
		for (var queue in htmlQueue) {
			container.append(htmlQueue[queue]);
		}
		// 上面的菜单
		// var topMenu = $("#" + MAP_BOTTOM_TOP_MENU),
		//获得左边的菜单
		var leftMenu = $("#" + MAP_BOTTOM_LEFT_MENU),
			//获得右边的菜单
			rightMenu = $("#" + MAP_BOTTOM_RIGH_MENU);
		leftMenu.append(LEFT_MENU);
		rightMenu.append(RIGHT_MENU);
		// 添加按钮
		addLayerForm = document.getElementById('left-menu-layer-add-form');
		addLayerBtn = $("#addLayer");
		addLayerBtn.addClass(DISABLE_BTN);
		LEFT_TREE_MENU_OBJ = $(LEFT_TREE_MENU);
		//添加单元的表单
		addItemForm = document.getElementById('left-menu-add-form');
		//多边形菜单的表单内容
		polylineForm = document.getElementById('polyline-menu-add-form');
		//锚点的表单内容
		pointerForm = document.getElementById('pointer-menu-add-form');
		//热力图的表单内容
		heatForm = document.getElementById('heat-menu-add-form');
		//蚂蚁路径
		antPathForm = document.getElementById('antPath-menu-add-form');
		//多边形的点数列表
		polylineList = $("#polyline-menu-list");
		//锚点的数目列表
		pointerList = $("#pointer-menu-list");
		//已完成的多边形列表
		polygonList = $("#polygon-menu-list");
		//作用于圆形的表单表单
		circleForm = document.getElementById("circle-menu-add-form");
		//记录已经绘制出的圆形
		circleList = $("#circle-menu-list");
		//记录已经完成的蚂蚁点
		antPointList = $("#ant-point-menu-list");
		//记录已经完成的蚂蚁路径
		antPathList = $("#ant-path-menu-list");
		//添加描述的表单
		shapItemForm = document.getElementById("shap-item-desc-form");
		//蚂蚁线参数列表
		antPathOptionsForm = document.getElementById("shap-item-antPath-form");
	}

	mapUI.prototype.render = function(config) {
		gloalConfig = config;
		checkParam(config);
		generateUI(config);
	}

	/**
	 * 保存数据,将当前已激活的地图的数据保存
	 */
	function saveData() {
		exportRaw(TextNode.TIP30, JSON.stringify(leftItemHtmlOperator.encode()));
	}


	/**将外部导入的数据，初始化到当前激活的地图中
	 * @param {Object} data
	 */
	function importData(data) {
		//外部的数据加载进来，生成对应的元素对象，这里假设是完整的，正确的json对象

		//获得对应的mapid
		var mapId = data.id,
			mapCfg = data.cfg,
			mapData = data.data;

		// 判断地图是否已经加载
		if (tabMap[mapCfg.id]) {
			layer.msg(TextNode.TIP28);
			return;
		} else {
			tabMap[mapCfg.id] = {
				obj: null,
				cfg: mapCfg,
				act: {
					actForm: null, //当前正在编辑的表单
					actPaint: null //正在使用的绘画方法
				}
			}
		}
		element.tabAdd('map-tab', {
			title: mapCfg.name,
			content: '<div id="map' + mapCfg.id + '" style="cursor:default;"></div>',
			id: mapCfg.id //实际使用一般是规定好的id，这里以时间戳模拟下
		});
		element.tabChange('map-tab', mapCfg.id);
		var map = tabMap[mapId].obj = L.map('map' + mapCfg.id, mapCfg.opt).setView(mapCfg.view, mapCfg.zoom);
		L.tileLayer(mapCfg.url, {
			tileSize: 512,
			noWrap: true
		}).addTo(map);
		map.on('click', editMap);
		//开始创建这个地图
		//数据部分可以直接设置，但是界面部分需要根据基础数据来重新创建
		leftItemHtmlOperator.setMap(mapId, mapData);
		var baseData = leftItemHtmlOperator.getMap(mapId),
			layerBodyMap = {}; // layerId -> type,bodyId
		// 图层的初始化
		for (var layerId in baseData) {
			var dd = baseData[layerId],
				d = {
					title: dd.title,
					id: layerId, //区别内容的id
					bodyId: layerId.replace(LAYER, ''),
				};
			laytpl(LEFT_LAYER_ITEM).render(d, function(html) {
				LEFT_TREE_MENU_OBJ.append(html);
				//将对象放在本地
				leftItemHtmlOperator.insertLayerElement(mapId, d.id, {
					obj: $("#" + d.id),
					bodyObj: $("#" + d.bodyId),
					kids: {}
				});

				//表示这个的类已经开辟出来了，接下来初始化kids下面的类
				var layerHtml = leftItemHtmlOperator.getLayer(layerId),
					kids = layerHtml.kids,
					layerElement = leftItemHtmlOperator.getLayerElement(layerId),
					layerBody = layerElement.bodyObj;
				//对依靠数据来开辟下方模型数据
				for (var bodyId in kids) {
					//这里的kid对应的是bodyId
					var kid = kids[bodyId],
						type = kid.type,
						name = kid.name,
						localRare = dropRareMappingValue[kid.rare];
					laytpl(LEFT_LAYER_SHAPE_ITEM).render({
						id: bodyId,
						layerId: layerId,
						name: name,
						rt: type,
						rare: localRare.name,
						rareClass: localRare.cln,
						bClass: localRare.bln,
						iurl: kid.iurl,
						type: dropMapping[type]
					}, function(html) {
						layerBody.append(html);
						//面板和数据挂钩起来
						leftItemHtmlOperator.insertBodyElement(mapId, layerId, bodyId, {
							obj: $("#" + bodyId), //面板
						});
						//初始化图形
						var shapeName = dropMappingValue[type];
						leftItemHtmlOperator.initDataElement(mapId, layerId, bodyId, shapeName);
						//为某个图形开辟了空间，为他创建对象和界面UI
						leftItemElement[shapeName].init(mapId, layerId, bodyId, kid);
						form.render();
					});
				}
			});

		}
		// 放开禁用
		addLayerBtn.removeClass(DISABLE_BTN);
	}

	function exportRaw(name, data) {
		var urlObject = window.URL || window.webkitURL || window;
		var export_blob = new Blob([data]);
		var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
		save_link.href = urlObject.createObjectURL(export_blob);
		save_link.download = name;
		fakeClick(save_link);
	}

	function destoryIconContainer() {
		//选择图标的弹出框进行销毁
		if (iconContainer) {
			iconContainer.remove();
			iconContainer = null;
		}
		if (iconContainer0) {
			iconContainer0.remove();
			iconContainer0 = null;
		}
	}

	function fakeClick(obj) {
		var ev = document.createEvent("MouseEvents");
		ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		obj.dispatchEvent(ev);
	}
	document.oncontextmenu = function() {
		return false
	}
	document.onkeydown = function(e) {
		var keyCode = e.keyCode || e.which || e.charCode;
		var ctrlKey = e.ctrlKey || e.metaKey;
		if (isEdit) {
			if (ctrlKey && keyCode == 83) {
				//保存内容，首先要有正在编辑的图层
				if (currentPaint) {
					saveData();
				} else {
					layer.msg(TextNode.TIP29);
				}
				e.preventDefault();
			}
		}
		// return false;
	}
	var UI = new mapUI();
	exports(MODULE_NAME, UI);
});
